| 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
|
|
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%
|
 |
 |
|
|
subject: <? super T>
|
|
|