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>>
?
Asked
Active
Viewed 263 times
1

user2018791
- 1,143
- 15
- 29
-
2I suspect this is fallout from http://stackoverflow.com/questions/3061759/why-in-java-enum-is-declared-as-enume-extends-enume. – Oliver Charlesworth Sep 05 '16 at 11:59
2 Answers
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