I noticed the specificaition for Collections.sort:
public static void sort(List list, Comparator super T> c)
Why
It's obvious to you that, in the case of Comparator
, any ancestor of T
would work. But the compiler doesn't know that class Comparator
functions like that - it just needs to be told whether it should allow
or super T>
.
Viewed another way, yes it's true that any Comparator
of an ancestor would work in this case - and the way the library developer says that is to use super T>
.