Use of super in Comparator in java

The term ? super T means "unknown type that is, or is a super class of, T", which in generics parlance means its lower bound is T.

This signature is used because T may be assigned to, and compared with, any variable whose type is, or is a super class of, T. Ie if a Comparator can accept a super class of T in its compare() method, you can pass in a T.

This follows the PECS mnemonic: "Producer Extends, Consumer Super", which means that producers of things should work with things that have an upper bound ( ? extends T) and consumers (like comparator implementations that use things) should work with lower bounds ( ? super T).


In here < ? super T> means generics - NOT comparisons.

It means you have a Comparator with a generic type of ? super T (something that extends is super typed by T), as explained in this thread

comp is the variable name (binding).

So basically in here Comparator < ? super T> is a type and comp is an identifier (variable name), that is of type Comparator <? super T>


For more info: Java Generics