user2018791
user2018791

Reputation: 1153

Enum implements Comparable<E> why not Comparable<Enum<E>>

Usually, when a class implements Comparable, the type variable T is the class name, for example, String implements Comparable<String>, Long implements Comparable<Long>, Date implements Comparable<Date>,then why Enum implements Comparable<E> not Comparable<Enum<E>> ?

Upvotes: 1

Views: 279

Answers (2)

chiastic-security
chiastic-security

Reputation: 20520

It's because the enum class is defined as

public abstract class Enum<E extends Enum<E>> ...

So the E is already an Enum<E>, and having it implement Comparable<E> already implicitly has the Enum part inside it.

You might want to look at this question for further information on why it's declared in this recursive fashion (because it does rather hurt the brain).

Upvotes: 0

Peter Lawrey
Peter Lawrey

Reputation: 533660

E is an Enum<E> already.

The reason it cannot be Enum<E> as that implies any Enum<E> is comparable which only E is acceptable.

Upvotes: 2

Related Questions