Are there any downsides if we add Enum.name() to the list of constant expressions in the JLS?
David Alayachew
davidalayachew at gmail.com
Thu Oct 17 00:09:25 UTC 2024
Hello Amber Dev Team,
In Java 23 JLS 15.29, it says that a constant expression can only be made
up of primitive LITERALS, String LITERALS, a couple of operations, and
CONSTANT VARIABLES.
The word LITERAL means that, for strings, I need to put in the full double
quotes (or triple double quotes for textblocks) in order to qualify.
And the word constant variable is defined in 4.12.4. "A constant variable
is a variable of primitive type or type String that is initialized with a
constant expression", which is what 15.29 is, mentioned above.
Now, to my question -- are there any downsides or obstacles to adding
Enum.name() to this list of constant expressions?
Enum.name() is a final method, and we know for a fact that, if the class
compiles, then it ALWAYS outputs the same value. And therefore, it seems
like it aligns nicely with the goals and intents of constant variables. Is
there anything bad or wrong about adding enum.name() to the list?
I do see some ways that it would provide value, but for now, I just want to
get an idea of if it would be bad or wrong to do before seeing if it is
worth it at this point in time.
Finally, apologies for not having done any preview feature testing lately.
I have been juggling personal and work emergencies nonstop. Only recently
had a chance to poke my head out from the bomb shelter, and I'm probably
going to jump back in shortly.
Thank you for your time and help.
David Alayachew
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/amber-dev/attachments/20241016/9ee59bd6/attachment-0001.htm>
More information about the amber-dev
mailing list