PROPOSAL: Abstract enums (version 2)

Derek Foster vapor1 at teleport.com
Wed May 6 01:08:02 PDT 2009


Howard,

Bruce pretty much has it right. Extending an arbitrary Java class pretty much wouldn't work, for the reasons he describes.

I considered writing my proposal in such a way as to allow an enum to extend certain kinds of classes (those which were generified in just the right way, and which ultimately had Enum at the top of the inheritance hierarchy), but it seemed to me that forcing the user to repeat all of that boilerplate code, exactly right ("abstract class Foo<T extends Foo<T>> extends Enum<T> { whatever } and so forth) was an unreasonable burden to expect a programmer to have to put up with. The "abstract enum" syntax allows the compiler to generate that boilerplate code without the user having to know it exists, in a similar fashion to how the normal "enum" keyword allows the user to not  have to deal with the "Enum<T extends Enum<T>>" nastiness of the Enum superclass.

Derek

-----Original Message-----
>From: Bruce Chapman <brucechapman at paradise.net.nz>
>Sent: May 1, 2009 3:25 AM
>To: 
>Cc: coin-dev at openjdk.java.net
>Subject: Re: PROPOSAL: Abstract enums (version 2)
>
>Howard Lovatt wrote:
>> Derek,
>>
>> I have found also wanted to extend an abstract class when using enums.
>> However I ideally didn't want to extend a special enum abstract class, e.g.
>>
>> abstract enum Super { ... } // Has enum
>>
>> enum extends Super { ... }
>>
>> But rather any old abstract class:
>>
>> abstract class Super { ... } // No enum
>>
>> enum extends Super { ... }
>>
>> What is the rational for only allowing abstract enum to be extended rather
>> than a plain abstract class.
>>   
>Because if an enum could extend any abstract class, then it wouldn't 
>always be possible to also extend java.lang.Enum<E extends Enum<E>>, and 
>the language spec says (currently) "The direct superclass of an enum 
>type named /E/ is |Enum<E>"|, and Enum's class apidoc says "This is the 
>common base class of all Java language enumeration types."
>
>Bruce
>>  -- Howard.
>>
>>   
>
>




More information about the coin-dev mailing list