<div dir="ltr"><div dir="ltr">On Wed, Oct 16, 2024 at 7:09 PM David Alayachew <<a href="mailto:davidalayachew@gmail.com">davidalayachew@gmail.com</a>> wrote:</div><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="auto">Now, to my question -- are there any downsides or obstacles to adding Enum.name() to this list of constant expressions?</div></blockquote><div><br></div><div>Just to clarify, this could only work for enum constant literals, e.g., <span style="font-family:monospace">FOOBAR.name()</span> which would obviously have value <span style="font-family:monospace">"foobar"</span>.</div><div><br></div><div>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.<br></div><div><br></div><div>To give a concrete example, this program, which now compiles:<br></div><div><br></div><div style="margin-left:40px"><span style="font-family:monospace">enum Test {<br>    AAA;<br>    void meth2() {<br>        final String s = AAA.name();<br>        while (s == "AAA") { }<br>        System.out.println("done");<br>    }<br>}<br></span></div><div><br></div><div>would start failing to compile like this:</div><div><br></div><div style="margin-left:40px"><span style="font-family:monospace">Test.java:6: error: unreachable statement<br>        System.out.println("done");<br>        ^</span></div><div><br></div><div>An equally relevant question is: what is the upside? Is there a scenario you have in mind where this would lead to an improvement?</div><div><br></div><div>-Archie<br></div><br></div><span class="gmail_signature_prefix">-- </span><br><div dir="ltr" class="gmail_signature">Archie L. Cobbs<br></div></div>