Java Solaris Communities Sun Store Join SDN My Profile Why Join?
 
Bug Database
Bug Detail
Quick Lists
Top 25 Bugs
Top 25 RFE's
Recently Closed Bugs
Printable Page Printable Page


Bug Database
Bug ID: 6222244
Votes 0
Synopsis allow "abstract enum AbstractEnum" and "enum MyEnum extends AbstractEnum"
Category java:specification
Reported Against
Release Fixed
State 11-Closed, Will Not Fix, request for enhancement
Priority: 4-Low
Related Bugs 6507006 , 6570766
Submit Date 27-JAN-2005
Description
A DESCRIPTION OF THE REQUEST :
Allow the declaration of  "abstract enum" classes where the implementation of the "enum" class is implemented. Specifying values in the "abstract enum" should be disallowed.

The "actual" enum class could extend the "abstract enum" class and add the declaration of the enum values.


JUSTIFICATION :
The usefullness of the fact that enums are just classes is very limited by the fact that the complete implementation _must_ reside in the enum class itself.

It is currently not possible to make different enums share the same implementation. If I have multiple enum classes that differ only in enum values but have the same implementation I must copy the implementation code in all enum classes. Not very maintainable!

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
This should compile:

abstract enum MyEnumImpl {
  private int value;

  MyEnumImpl(int value) {
    this.value = value;
  }

  public int getValue() { return value; }
}

enum MyEnum extends MyEnumImpl {
  ONE(1),
  TWO(2)
}
ACTUAL -
"abstract enum MyAbstractEnum" is disallowed
"enum MyEnum extends MyAbstracEnum" is disallowed

CUSTOMER SUBMITTED WORKAROUND :
Copy the implementation code in every enum class
  xxxxx@xxxxx   2005-1-27 09:43:04 GMT
Work Around
N/A
Evaluation
JSR201 deliberately restricted Enums in terms of subclassing etc. I doubt if we will re-open this can of worms again.

  xxxxx@xxxxx   2005-04-26 18:22:13 GMT
See evaluation in 6507006.
Posted Date : 2007-06-19 12:20:22.0
Comments
  
  Include a link with my name & email   

Submitted On 16-JUN-2005
Bernhard.Mandl
The main problem with subclassing enums is that  this would break the contract that you may compare enumerated values with 


Submitted On 16-JUN-2005
Bernhard.Mandl
The main problem with subclassing enums is that  this would break the contract that you may compare enumerated values by comparing for equal references. The number of values in the enumeration should also be constant and not extendable by subclassing.

These problems would NOT affect abstract enumerations becasue these contain only code to be inherited, but no enumerated values.

So why not keep the bug-id open as RFE? What's the problem?



Submitted On 26-MAY-2007
steevcoc
I see  Bernhard.Mandl point above:

The subclass is limited to only one child level. There can be no grandchildren to conflict.


Submitted On 01-AUG-2007
I strongly support this RFE, I often have a need for this. It isn't a can of worms at all.  Just let

    abstract enum EnumA extends Enum { ... }

expand to a class

    abstract class EnumA<E extends EnumA<E>> extends Enum<E> { ... }

and

    abstract enum EnumB extends EnumA { ... }

to a class

    abstract class EnumB<E extends EnumB<E>> extends EnumA<E> { ... }

and finally

    enum EnumC extends EnumB { ... }

to a conrete enum class

    class EnumC extends EnumB<EnumC> { ... }

and you're set. Of course Enum.valueOf() and Class.getEnumConstants() would only be applicable to concrete enum types.

Please reopen this RFE!



PLEASE NOTE: JDK6 is formerly known as Project Mustang