I can't see any difference between this default sort method(from java.util.Collections)
public static <T extends Comparable<? super T>> void sort(List<T> list) {
//implementation
}
..and this :
public static <T extends Comparable<T>> void mySort(List<T> list) {
//implementation
}
Although I know about the differences between the 'upper' and 'lower' bounded wildcards,I still don't understand why they use '? super T' instead of simple 'T' in this case.If I use these methods,I get the same result with both of them.Any suggestions?
With your version, the following will not compile:
class Base implements Comparable<Base> { ... }
class Derived extends Base { ... }
List<Derived> list = ...;
mySort(list);
Derived
does not extend Comparable<Derived>
. However, it does extend Comparable<Base>
(and thus, Comparable<? super Derived>
).
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments