public static<T extends Comparable<? super T>> void sort(List<T> list )
This sort method takes a List that contains T. So, what is T? T is any type that extends Comparable<T>.
If T is not a comparable, it won't compile.
Here are my analysis:
1. During compilation of this sort method, the compiler does not know what exactly T is. If you pass List<Integer> myIntList to sort method, it will compile because Integer is a comparable.
If you pass in List<Animal> where Animal is not a comparable, it won't compile.
2. What is mean by Comparable<? super T>? I think you can treat it as Comparable<T>. Based on M&R's study guide, Comparable<T> IS-A Comparable<? super T>.
You may understand this better : T extends Comparable<T>. Integer class implements Comparable<Integer>, so as Double,
String, Float....
But this one "scares" me : T extends Comparable<? super T>. I may think if T is an integer , will T extends Comparable <Object>? Comparable<? super Integer> can be assigned to Comparable<Object> type. But somehow, it does not make sense to say Integer is a type of Comparable<Object> because Integer implements Comparable<Integer>.
3.There is another important key point I want to make: Comparable<Integer> is not a Comparable<Object>.
For the exam, I guess it may not be that difficult (KB never put this type of question in their book).....I think....But it is good to learn just in case.
Can anyone verify what I write?