1

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>> ?

user2018791
  • 1,143
  • 15
  • 29

2 Answers2

2

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.

Peter Lawrey
  • 525,659
  • 79
  • 751
  • 1,130
0

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

Community
  • 1
  • 1
chiastic-security
  • 20,430
  • 4
  • 39
  • 67