JDK-6222244 : allow "abstract enum AbstractEnum" and "enum MyEnum extends AbstractEnum"
  • Type: Enhancement
  • Component: specification
  • Sub-Component: language
  • Affected Version: 5.0
  • Priority: P4
  • Status: Closed
  • Resolution: Won't Fix
  • OS: windows_xp
  • CPU: x86
  • Submitted: 2005-01-27
  • Updated: 2007-06-19
  • Resolved: 2005-04-26
Related Reports
Duplicate :  
Relates :  
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
###@###.### 2005-1-27 09:43:04 GMT

Comments
EVALUATION See evaluation in 6507006.
19-06-2007

EVALUATION JSR201 deliberately restricted Enums in terms of subclassing etc. I doubt if we will re-open this can of worms again. ###@###.### 2005-04-26 18:22:13 GMT
26-04-2005