tags:

views:

625

answers:

1

Possible Duplicate:
add values to enum

Why enums in Java cannot inherit from other enums? Why is this implemented this way?

+2  A: 

Example stolen from here

Because adding elements to an enum would effectively create a super class, not a sub class.

Consider:

 enum First {One, Two}   
 enum Second extends First {Three, Four}   

 First a = Second.Four;   // clearly illegal 
 Second a = First.One;  // should work

This is the reverse of the way it works with regular classes. I guess it could be implemented that way but it would be more complicated to implement than it would seems, and it would certainly confuse people.

TofuBeer
Java enums are compiled to regular old Java classes, with each value in the enum as a public static field. That might clarify things to the OP - it does to me.
Matt Ball