The signature of java.util.Collections.max looks like this:
public static <T extends Object & Comparable<? super T>> T max(Collection collection);
From what I understand, it basically means that T must be both a java.lang.Object and a java.lang.Comparable<? super T>>,
However, since every java.lang.Comparable is also an java.lang.Object, what is the difference between the signature above and this below? :
public static <T extends Comparable<? super T>> T max(Collection collection);
super T denotes an unknown type that is a supertype of T (or T itself; remember that the supertype relation is reflexive). It is the dual of the bounded wildcards we've been using, where we use ? extends T to denote an unknown type that is a subtype of T .
The extends keyword extends a class (indicates that a class is inherited from another class). In Java, it is possible to inherit attributes and methods from one class to another. We group the "inheritance concept" into two categories: subclass (child) - the class that inherits from another class.
There is no difference whatsoever. extends Object is redundant and assumed otherwise, just like writing class F extends Object . I would bet they are equivalent, since all classes in Java implicitly extend Object . No difference at all, it is the consequence of language design/grammar.
extends Object> means you can pass an Object or a sub-class that extends Object class. ArrayList<? extends Number> numberList = new ArrayList<Number>(); //Number of subclass numberList = new ArrayList<Integer>(); //Integer extends Number numberList = new ArrayList<Float>(); // Float extends Number.
To preserve binary compatibility: It's completely described here. The second signature actually changes the return type of the method to Comparable and it loses the generality of returning an Object. The original signature preserves both.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With