Zaghie
Zaghie

Reputation: 38

Java Comparable Type

Does anyone have a link for the java Comparable<T> type? I can only find documentation concerning the interface. I require information concerning Objects of type Comparable, not objects that implement the Comparable interface.

For example:

Comparable element = "6";

Eclipse allows that expression, although it gives a warning that it must be parameterized, (i.e. Comparator<T>). Does anyone have an explanation?

Upvotes: 0

Views: 728

Answers (1)

Eran
Eran

Reputation: 393956

Comparable is an interface, not a class. You can assign the String "6" to a Comparable variable because String implements Comparable<String>.

Specifying the type parameter will get rid of the warning :

Comparable<String> element = "6";

Upvotes: 4

Related Questions