1

I was going through the Collections class and found this method max. From the method signature, I understand that we can only pass the collection of those classes which implement Comparable interface of the same type or its parent classes.

public static <T extends Object & Comparable<? super T>> T max(Collection<? extends T> coll)

But what I don't get is this:

Collection<? extends T> coll

From my understanding, this means that we can pass collection of any type which has implemented Comparable interface (of the same type or it's superclasses) or its child classes. If parent has satisfied this criteria, does it not mean that all the child classes have also satisfied the same criteria? Why can't it be just

public static <T extends Object & Comparable<? super T>> T max(Collection<T> coll)

Is it written like this so that elements cannot be added to the coll object inside this method?

Henry Twist
  • 5,666
  • 3
  • 19
  • 44
skgv
  • 47
  • 1
  • 3

0 Answers0