32

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);

0

1 Answer 1

33

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.

Sign up to request clarification or add additional context in comments.

3 Comments

Thanks for the link =) Btw are you aware of any tools to examine the erased signatures after compilation?
Not that I know of, but maybe this can give some clues on the topic. I also suggest reading the section on "Type Erasure" at Angelika Langer's Generics FAQ.
@Pacerier, yes, use "javap -s".

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.