hg: valhalla/valhalla/langtools: Values types must be "all final".

Remi Forax forax at univ-mlv.fr
Thu Jul 31 21:40:33 UTC 2014


On 07/31/2014 06:19 AM, Richard Steiger wrote:
> I'm new to this list, so may well have missed previous discussions 
> about the rationale for the "Value types must be all final" 
> pronouncement.
>
> While I'm not at all sure that value-type-finality is relevant to the 
> following, I'd like to go on record stating that one of the more 
> irritating aspects of the current enum semantics is the inability to 
> extend an existing enum type with additional values.   I appreciate 
> that there might be numerous subtleties that would need to be 
> addressed in making enums "not quite final", i.e. extensible in a 
> limited way (no overrides, etc.), the boon to application developers 
> and others seems to me to justify at least thinking-through the issues.

An enum enumerate all possible values thus you can not add a 
supplementary value by inheritance,
unlike an interface which let you provide the implementation you want an 
enum is a not an open type but a closed type.

 From the design point of view, your problem is not to allow inheritance 
on enum but why you (or any of our fellow dev) have chosen to use an 
enum to represent something you want to extend i.e. an open type.

In term of implementation having open enums is really hard, imagine that 
you have an enum Foo and two enums Bar and Baz
that inherits from Foo, how the compiler is suppose to provide the 
ordinal value in that case (don't forget that Bar and Baz can be 
compiled separately) ?
Trying to implement values() on an open enum is fun too.

regards,
Rémi

>
> On 7/30/2014 8:31 PM, Paul Benedict wrote:
>> I've been thinking about this. When it comes to how enums were 
>> speced, they
>> didn't need "final" or "class" specifiers (yes, an enum literal can be a
>> subclass but ignore that for now). So I am not sure all these explicit
>> qualifiers are helpful for writing value classes too. Granted, this 
>> is the
>> straw man implementation, but I would like to hear anyone's thoughts on
>> just making it "public value ClassName".
>> On Jul 30, 2014 5:08 PM, <paul.govereau at oracle.com> wrote:
>>
>>> Changeset: ecff516ac894
>>> Author:    pgovereau
>>> Date:      2014-07-30 17:05 -0400
>>> URL:
>>> http://hg.openjdk.java.net/valhalla/valhalla/langtools/rev/ecff516ac894
>>>
>>> Values types must be "all final".
>>>
>>> ! src/share/classes/com/sun/tools/javac/comp/TransValues.java
>>> ! src/share/classes/com/sun/tools/javac/resources/compiler.properties
>>> + test/tools/javac/diags/examples/ValueFinal.java
>>> + test/tools/javac/valhalla/values/CheckFInal.out
>>> + test/tools/javac/valhalla/values/CheckFinal.java
>>> + test/tools/javac/valhalla/values/CheckFinal.out
>>>
>>>
>



More information about the valhalla-dev mailing list