Why List.sort() use Comparator<? super E>
instead of Comparator<? extends E>
or just Comparator<E>
?
If a List<E>
contains elements of type E or its sub-types, Comparator should only expect type E or its sub-types, in its compare method call.
For example: For a list of type Integer, why would I need a Comaparator<Object>
or Comparator<Number>
when List<Integer>
can only have Integer or its sub-type?
This is not a duplicate question, please read discussion in comment section.