Are there any downsides if we add Enum.name() to the list of constant expressions in the JLS?
Archie Cobbs
archie.cobbs at gmail.com
Thu Oct 17 01:33:09 UTC 2024
On Wed, Oct 16, 2024 at 7:09 PM David Alayachew <davidalayachew at gmail.com>
wrote:
> Now, to my question -- are there any downsides or obstacles to adding
> Enum.name() to this list of constant expressions?
>
Just to clarify, this could only work for enum constant literals, e.g.,
FOOBAR.name() which would obviously have value "foobar".
One downside is this could make certain programs no longer compile. These
programs may be "oddballs" but still this would represent a backward
incompatibility, which is a pretty big no-no in Java-land.
To give a concrete example, this program, which now compiles:
enum Test {
AAA;
void meth2() {
final String s = AAA.name();
while (s == "AAA") { }
System.out.println("done");
}
}
would start failing to compile like this:
Test.java:6: error: unreachable statement
System.out.println("done");
^
An equally relevant question is: what is the upside? Is there a scenario
you have in mind where this would lead to an improvement?
-Archie
--
Archie L. Cobbs
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/amber-dev/attachments/20241016/b93f7cd9/attachment.htm>
More information about the amber-dev
mailing list