JEP 301: Enhanced Enums

Maurizio Cimadamore maurizio.cimadamore at
Thu Dec 8 11:13:19 UTC 2016

On 08/12/16 07:23, forax at wrote:
> Enum were not created to be a short syntax for encoding a hierarchy, and to avoid that, the EG that introduces the Enum feature make it clear by forcing all values of an enum to be typed with the enum type.
> And as Josh Blosch said in the video, they also wanted to allow to encode what Josh calls 'named function' by allowing abstract enums. Name functions are not useful anymore, because now we have full real lambdas. So there is no reason to use abstract enums anymore, no reason to have enum values with different subclasses even if i agree with you that the syntax for that is short and cool.
One thing is to say no to enum subclassing. I agree that is the right 
decision - when you want to operate on enum constants, you should live 
in a world where the universe of constants if known statically, 
otherwise it all falls down. Another thing is to say that the extra 
information we have about enum constants at compile-time should be 
thrown away. That is the part of your argument I disagree with - and I'm 
having troubles seeing what 'erasing' the enum constant type buys you.

On the other hand, not erasing the type _does_ buy you something; in 
addition to the examples already mentioned, another common use case is 
to be able to reuse code inside enums:

Of course, if your position is that nobody should ever use bodies in 
enum constants, then I think there's nothing for you to look at here :-)


More information about the platform-jep-discuss mailing list