<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
<style type="text/css" style="display:none;"> P {margin-top:0;margin-bottom:0;} </style>
</head>
<body dir="ltr">
<div style="font-family: "Calibri Light", "Helvetica Light", sans-serif; font-size: 12pt; color: rgb(0, 0, 0);" class="elementToProof">
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);" class="elementToProof">
<a href="https://cr.openjdk.org/~mcimadamore/amber/enhanced-enums.html#too-raw">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);" class="elementToProof">
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);" class="elementToProof">
<br>
</div>
<div style="font-family: "Calibri Light", "Helvetica Light", sans-serif; font-size: 12pt; color: rgb(0, 0, 0);" class="elementToProof">
Regards</div>
<div id="appendonsend"></div>
<hr style="display:inline-block;width:98%" tabindex="-1">
<div id="divRplyFwdMsg" dir="ltr"><font face="Calibri, sans-serif" style="font-size:11pt" color="#000000"><b>From:</b> amber-dev <amber-dev-retn@openjdk.org> on behalf of Clement Cherlin <ccherlin@gmail.com><br>
<b>Sent:</b> Sunday, February 22, 2026 12:21 PM<br>
<b>To:</b> amber-dev@openjdk.org <amber-dev@openjdk.org><br>
<b>Subject:</b> Enhanced Enums Redux (with working code)</font>
<div> </div>
</div>
<div>
<div dir="ltr">
<div dir="ltr">
<div>Greetings,</div>
<div><br>
</div>
<div>I have been working on the problem of generic enums off and on for quite some time (see <a href="https://github.com/Mooninaut/cursed-generic-enum-java" target="_blank">https://github.com/Mooninaut/cursed-generic-enum-java</a> for a previous dead-end attempt).</div>
<div><br>
</div>
<div>I think I have an actual solution this time, and it doesn't require any changes to Java's type system. It only requires a slight tweak to the "extends" clause of generic enums: Replace "extends Enum<SomeEnum<T>>" with "extends Enum SomeEnum<?>>".</div>
<div><br>
</div>
<div>I have a fully-worked example of this at <a href="https://github.com/Mooninaut/java-generic-enums" target="_blank">https://github.com/Mooninaut/java-generic-enums</a> implementing the example given in <a href="https://mail.openjdk.org/pipermail/amber-spec-experts/2017-May/000041.html" target="_blank">https://mail.openjdk.org/pipermail/amber-spec-experts/2017-May/000041.html</a>,
which was the stopping point for the original generic enums effort.</div>
<div><br>
</div>
<div>I included lightly modified copies of Enum, EnumSet and EnumSet's subclasses, and a Main class which demonstrates that the original problems with collections of enums are almost entirely resolved.</div>
<div><br>
</div>
<div>I also provide several generic enums with non-trivial type bounds to demonstrate that generic enums are no more limited than any other generic class.</div>
<div><br>
</div>
I cannot say definitively that every conceivable generic type will work, but I haven't yet found any generic enum that wouldn't compile and run successfully.</div>
<div dir="ltr"><br>
</div>
<div>There is one slightly awkward issue. It's not possible to simply pass an enum class literal to EnumSet's static factory methods without a raw cast.</div>
<div><br>
EnumSet.allOf((Class<Option<?>>) (Class) Option.class);</div>
<div><br>
</div>
<div>But this can be worked around by taking advantage of the fact that getDeclaringClass casts to Class<E></div>
<div><br>
</div>
<div>EnumSet.allOf(Option.D.getDeclaringClass());</div>
<div dir="ltr"><br>
</div>
<div>Cheers,</div>
<div>Clement Cherlin</div>
</div>
</div>
</body>
</html>