<div dir="ltr"><div dir="auto"><div><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Sun, Feb 22, 2026, 2:26 PM Chen Liang <<a href="mailto:chen.l.liang@oracle.com" rel="noreferrer" target="_blank">chen.l.liang@oracle.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<div dir="ltr">
<div style="font-family:"Calibri Light","Helvetica Light",sans-serif;font-size:12pt;color:rgb(0,0,0)">
Hi Clement, I think the issue you've discovered is already considered in the original proposal, in the "Too raw?" section:</div>
<div style="font-family:"Calibri Light","Helvetica Light",sans-serif;font-size:12pt;color:rgb(0,0,0)">
<a href="https://cr.openjdk.org/~mcimadamore/amber/enhanced-enums.html#too-raw" rel="noreferrer noreferrer" target="_blank">https://cr.openjdk.org/~mcimadamore/amber/enhanced-enums.html#too-raw</a></div>
<div style="font-family:"Calibri Light","Helvetica Light",sans-serif;font-size:12pt;color:rgb(0,0,0)">
TLDR; a reifiable type doesn't work with class literals.</div>
<div style="font-family:"Calibri Light","Helvetica Light",sans-serif;font-size:12pt;color:rgb(0,0,0)">
<br>
</div>
<div style="font-family:"Calibri Light","Helvetica Light",sans-serif;font-size:12pt;color:rgb(0,0,0)">
Regards</div></div></blockquote></div></div><div dir="auto"><br></div><div dir="auto">That conclusion should be revisited. Reifiable types work perfectly fine with class literals, as long as you're willing to cast class literals to unerased types, and accept the fact that unerased types only truly exist at compile time. That's nothing new; all Java generics only truly exist at compile time (ignoring reflection).</div><div dir="auto"><br></div><div dir="auto">The only significant flaw would be if users were required to perform the awkward erased-to-raw-to-unerased cast every time they wanted to use EnumSet/EnumMap. But they don't. The method EnumClass.CONSTANT.getDeclaringClass(), a method which
already exists, has exactly the desired properties. It produces the correct statically-typed cast of EnumClass.class, suitable for use in any API that requires a properly-typed Class literal, such as EnumSet, without any modification to either existing JDK code or the Java type system.</div><div dir="auto"><br></div><div>As proof, I submit <a href="https://github.com/Mooninaut/java-generic-enums/blob/main/src/main/java/org/duckdns/mooninaut/genericEnum/Argument.java">https://github.com/Mooninaut/java-generic-enums/blob/main/src/main/java/org/duckdns/mooninaut/genericEnum/Argument.java</a></div><div><br></div><div>The claim "While in principle we could tweak the supertype of a generic enum to be Enum<Foo<?>> instead of Enum<Foo>, doing so would quickly run out of gas when considering examples such as the stream method chain shown above" is shown to be inaccurate.</div><div><br></div><div>The code</div><div><br></div><div>Arrays.stream(Argument.values())<br> .filter(a -> Number.class.isAssignableFrom(a.getClazz()))<br> .collect(toCollection(() -> MyEnumSet.noneOf(Argument.STRING_ARGUMENT.getDeclaringClass())));</div><div><br></div><div>compiles and executes with no issues.</div><div><br></div><div>It's inelegant, but it works. If elegance were required to adopt a feature into the JDK, we certainly wouldn't have generics in their current form.</div><div><br></div><div>Cheers,</div><div>Clement Cherlin</div></div>
</div>