aspose file tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes <? super T> Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Reply Bookmark "<? super T>" Watch "<? super T>" New topic
Author

<? super T>

Balaji Bang
Ranch Hand

Joined: Apr 23, 2007
Posts: 180
static
<T> int

binarySearch(List<? extends Comparable<? super T>> list, T key)

Here I understood that List argument in binarySearch() should implement Comparable.

1. What is the meaning of <? super T> after Comparable???

2. We can pass only List(ArrayList,Vector,LinkedList) to Collections.binarySearch and Collections.sort methods. we cannot pass Set and

Map. Correct??? Means we can only sort and search List only???
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 16680
    
  19

1. What is the meaning of <? super T> after Comparable???


Comparable itself, is also a generic. And the method is a generic method, that takes a type T. The first parameter is a List of sone type that extends Comparable, which is used to compare some type that is a super of the type specified by the generic method.

Henry


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
Ken Truitt
Ranch Hand

Joined: Aug 23, 2007
Posts: 124
...Comparable<? super T>... I believe signifies that whatever type it is that is passed in as a key to binarySearch()will implement Comparable generically, typing the interface for T or anything that T extends (superclasses).
Perhaps it is understood that Comparable is generic for type Object by default.

And that's right about Lists being the only type of Collection that works for sort. You would use the tree
implementations of Set and Map to get sorted content from those collections.


SCJP 88% | SCWCD 84%
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: <? super T>
 
Similar Threads
Is any difference? "wild card generics"
Generic Question
I don't see an advantage of Generics of Java 5 here!
Sorting a stack
Collections.binarySearch() problem