So, you understand that <T extends Comparable<T>> works with this class:
class Mammal extends Comparable<Mammal>
You now have a subclass of Mammal , Cat : class Cat extends Mammal . Because of inheritance, Cat also implements Comparable<Mammal> , and, as you said, it can compare with all mammals (including cats, of course) because of the compareTo(Mammal) method that it inherited from Mammal .
But now the problem is that Cat does not work with the <T extends Comparable<T>> binding, because Cat does not implement Comparable<Cat> . You cannot solve this problem if Cat implement Comparable<Cat> because you can implement an interface with only one type parameter.
But conceptually there is no problem sorting the Cat list, since Cat can be compared to another Cat (they can be compared to all mammals, which is more general, but the fact is that they can be compared to cats). Therefore, the problem is that our border is too restrictive.
<T extends Comparable<? super T>> <T extends Comparable<? super T>> solves this problem and allows you to use Cat . Recall the PECS rule - Manufacturer extends consumer super . Well, Comparable is a consumer, not a manufacturer, because you pass an argument of type T to its compareTo method (consume), but no methods should return a type T (produce). Therefore, the super pattern is suitable.
source share