<head><!-- BaNnErBlUrFlE-HeAdEr-start -->
<style>
  #pfptBanner8nifesh { all: revert !important; display: block !important;
    visibility: visible !important; opacity: 1 !important;
    background-color: #60beeb !important;
    max-width: none !important; max-height: none !important }
  .pfptPrimaryButton8nifesh:hover, .pfptPrimaryButton8nifesh:focus {
    background-color: #77a8c4 !important; }
  .pfptPrimaryButton8nifesh:active {
    background-color: #8193a0 !important; }
  html:root, html:root>body { all: revert !important; display: block !important;
    visibility: visible !important; opacity: 1 !important; }
</style>

<!-- BaNnErBlUrFlE-HeAdEr-end -->
</head><!-- BaNnErBlUrFlE-BoDy-start -->
<!-- Preheader Text : BEGIN -->
<div style="display:none !important;display:none;visibility:hidden;mso-hide:all;font-size:1px;color:#ffffff;line-height:1px;max-height:0px;opacity:0;overflow:hidden;">
On Mon, Feb 23, 2026 at 6: 26 AM Maurizio Cimadamore <maurizio. cimadamore@ oracle. com> wrote: Hi Clement On 22/02/2026 18: 21, Clement Cherlin wrote: > Greetings, > > I have been working on the problem of generic enums off and on</div>
<!-- Preheader Text : END -->

<!-- Email Banner : BEGIN -->
<div style="display:none !important;display:none;visibility:hidden;mso-hide:all;font-size:1px;color:#ffffff;line-height:1px;max-height:0px;opacity:0;overflow:hidden;">ZjQcmQRYFpfptBannerStart</div>

<!--[if ((ie)|(mso))]>
  <table border="0" cellspacing="0" cellpadding="0" width="100%" style="padding: 0px 0px 10px 0px; direction: ltr" lang="en"><tr><td>
    <table border="0" cellspacing="0" cellpadding="0" style="padding: 0px 8px 6px 8px; width: 100%; border-radius:4px; border-top:4px solid #8193a0;background-color:#60beeb;"><tr><td valign="top">
      <table align="left" border="0" cellspacing="0" cellpadding="0" style="padding: 0px 8px 4px 8px; font-size: 12px; line-height: 16px">
        <tr><td style="color:#000000; font-family: 'Arial', sans-serif; font-weight:bold; font-size:14px; line-height: 20px; direction: ltr">
          This Message Is From an Untrusted Sender
        </td></tr>
        <tr><td style="color:#000000; font-weight:normal; font-family: 'Arial', sans-serif; font-size:12px; direction: ltr">
          You have not previously corresponded with this sender.
        </td></tr>

      </table>
      <![if ie]><br clear="all"><![endif]>
      <table align="right" border="0" cellspacing="0" cellpadding="0" style="padding: 0px 0px 4px 0px; font-size: 14px; line-height: 36px"><tr>
        <td style="direction: ltr">  <a target="_blank" href="https://us-phishalarm-ewt.proofpoint.com/EWT/v1/ACWV5N9M2RV99hQ!Op20OCaAdslPvN5uut7-lUkKve0H_heFysa-45YIoCwqpIGTviQiuXDcxfMYIUFLnGJjHKKH8DCgidLTsRSNcNsYO9WzvkLashWa-DU_NFjQn1z0whs6SDyonaKbz0Y$" style="mso-padding-alt: 7px; padding: 7px; border-radius: 2px; border: 1px solid #666666; "><strong style="font-weight: normal; color: #000000; text-decoration: none; font-family: 'Arial', sans-serif; font-size: 14px;">  Report Suspicious  </strong></a>  ‌ </td>
      </tr></table>
    </td></tr></table>
  </td></tr></table>
<![endif]-->

<![if !((ie)|(mso))]>
  <div dir="ltr" lang="en" id="pfptBanner8nifesh" style="all: revert !important; display:block !important; text-align: left !important; margin: 0 0 10px 0 !important; padding:7px 16px 8px 16px !important; border-radius: 4px !important; min-width: 200px !important; background-color: #60beeb !important; background-color: #60beeb; border-top: 4px solid #8193a0 !important; border-top: 4px solid #8193a0;">
    <div id="pfptBanner8nifesh" style="all: unset !important; float:left !important; display:block !important; margin: 1px 0 1px 0 !important; max-width: 600px !important;">
      <div id="pfptBanner8nifesh" style="all: unset !important; display:block !important; visibility: visible !important; background-color: #60beeb !important; color:#000000 !important; color:#000000; font-family: 'Arial', sans-serif !important; font-family: 'Arial', sans-serif; font-weight:bold !important; font-weight:bold; font-size:14px !important; line-height:1.29 !important; line-height:1.29">
        This Message Is From an Untrusted Sender
      </div>
      <div id="pfptBanner8nifesh" style="all: unset !important; display:block !important; visibility: visible !important; background-color: #60beeb !important; color:#000000 !important; color:#000000; font-weight:normal; font-family: 'Arial', sans-serif !important; font-family: 'Arial', sans-serif; font-size:12px !important; line-height:1.5 !important; line-height:1.5; margin-top:2px !important;">
You have not previously corresponded with this sender.
      </div>

    </div>
    <div id="pfptBanner8nifesh" style="all: unset !important; float: right !important; display: block !important; display: block; margin-left: 16px !important; margin-top: 1px !important; text-align: right !important; width: fit-content !important; font-size: 12px !important">
<a id="pfptBanner8nifesh" href="https://us-phishalarm-ewt.proofpoint.com/EWT/v1/ACWV5N9M2RV99hQ!Op20OCaAdslPvN5uut7-lUkKve0H_heFysa-45YIoCwqpIGTviQiuXDcxfMYIUFLnGJjHKKH8DCgidLTsRSNcNsYO9WzvkLashWa-DU_NFjQn1z0whs6SDyonaKbz0Y$"
    style="all: unset !important; display: inline-block !important; text-decoration: none">
    <div class="pfptPrimaryButton8nifesh" style="display: inline-block !important; display: inline-block; visibility: visible !important; opacity: 1 !important; color: #000000 !important; color: #000000; font-family: 'Arial', sans-serif !important; font-family: 'Arial', sans-serif; font-size: 14px !important;  font-weight: normal !important; text-decoration: none !important; border-radius: 2px !important; margin-top: 3px !important; margin-bottom: 3px !important; margin-left: 16px !important; padding: 7.5px 16px !important; white-space: nowrap !important; width: fit-content !important;
        border: 1px solid #666666">
        Report Suspicious
    </div>
</a>
    </div>
    <div style="clear: both !important; display: block !important; visibility: hidden !important; line-height: 0 !important; font-size: 0.01px !important; height: 0px"> </div>
  </div>
<![endif]>

<div style="display:none !important;display:none;visibility:hidden;mso-hide:all;font-size:1px;color:#ffffff;line-height:1px;max-height:0px;opacity:0;overflow:hidden;">ZjQcmQRYFpfptBannerEnd</div>
<!-- Email Banner : END -->

<!-- BaNnErBlUrFlE-BoDy-end -->
<div dir="ltr"><div dir="ltr"><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Mon, Feb 23, 2026 at 6:26 AM Maurizio Cimadamore <<a href="mailto:maurizio.cimadamore@oracle.com" target="_blank">maurizio.cimadamore@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">Hi Clement<br>
<br>
On 22/02/2026 18:21, Clement Cherlin wrote:<br>
> Greetings,<br>
><br>
> I have been working on the problem of generic enums off and on for <br>
> quite some time (see <br>
> <a href="https://github.com/Mooninaut/cursed-generic-enum-java" rel="noreferrer" target="_blank">https://github.com/Mooninaut/cursed-generic-enum-java</a> for a previous <br>
> dead-end attempt).<br>
><br>
> I think I have an actual solution this time, and it doesn't require <br>
> any changes to Java's type system. It only requires a slight tweak to <br>
> the "extends" clause of generic enums: Replace "extends <br>
> Enum<SomeEnum<T>>" with "extends Enum SomeEnum<?>>".<br><br>I'd need more time to think about the consequences of this. That said, <br>
this has a good property, in that it only affects generic enum <br>
declarations. Non-generic enum would stay exactly the same.<br><br>
> There is one slightly awkward issue. It's not possible to simply pass <br>
> an enum class literal to EnumSet's static factory methods without a <br>
> raw cast.<br>
><br>
> EnumSet.allOf((Class<Option<?>>) (Class) Option.class);<br>
<br>
This makes me more worried -- because this is such a common idiom that <br>
(I think) has to work like for any other enum.<br>
<br>
In the spirit of your earlier suggestion, a possible way out would be to <br>
also redefine what Foo.class mean when Foo is a generic enum -- e.g. not <br>
just Class<Foo> (class-of-raw) but Class<Foo<?>> (class-of-wildcard).<br>
<br>
All such changes would  indeed help making generic enums more useful <br>
(and interoperable with EnumSet and friends), but whether all such <br>
changes are actually "sound", that's a different story.<br>
<br>
For instance, code like:<br>
<br>
MyEnumSet<Option> set = MyEnumSet.allOf(Option.class)<br>
<br>
Would _still_ fail. You need the LHS to be _exactly_ <br>
MyEnumSet<Option<?>> for this to work. Which means graduating an enum <br>
into a generic enum would still be a source incompatible change </blockquote><div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Cheers<br>
Maurizio</blockquote></div><div><br></div><div>That's an excellent point. Doing the migration in a single step is source incompatible.</div><div><br></div><div>However, it is possible to perform the migration in multiple steps, each step source</div><div>compatible with the previous step, allowing for gradual migration. This would</div><div>require multiple major releases of a library to complete. The result would be</div><div>that at each step, clients can update the library without incompatibility, as long</div><div>as they complete the required migration steps before upgrading to a major version</div><div>that takes the next migration step.</div><div><br></div><div>See <a href="https://github.com/Mooninaut/java-generic-enums/tree/main/src/main/java/org/duckdns/mooninaut/migration">https://github.com/Mooninaut/java-generic-enums/tree/main/src/main/java/org/duckdns/mooninaut/migration</a></div><div>for a step-by-step example.</div><div><br></div><div>Given a library that has an enum, which can usefully be migrated to a generic enum:</div><div><br></div><div>Step 1:</div><div>* Library changes method parameters of type "EnumSet<X>" (if any) to</div><div>  "EnumSet<? extends X>". This change is source-compatible for clients.</div><div>* Casts from "EnumSet<? extends X>" to "EnumSet<X>" may be</div><div>  required inside library methods.</div><div><div>* Suggestion: Some sort of @MigratingToGenericEnum annotation to prompt</div><div>  clients to update references, ideally with tool support.</div><br></div></div><div class="gmail_quote">Step 2:</div><div class="gmail_quote"><div>* Clients update library, and change variables of type "EnumSet<X>" to "EnumSet<? extends X>"<br>* Both "EnumSet<X>" and "EnumSet<? extends X>" compile.</div><div><br></div><div>Step 3:</div><div>* Library makes X generic, updates methods that return "EnumSet<X>" to</div><div>  return "EnumSet<X<?>>" This is source-compatible for clients that have completed</div><div>  step 2, with an unchecked warning on "EnumSet.allOf(X.class)" and related methods.<br>* Library methods may require casts from "EnumSet<? extends X>" to "EnumSet<X<?>>"<br>* Library changes "EnumSet.allOf(X.class)" to "EnumSet.allOf(X.CONSTANT.getDeclaringClass())"</div><div>* Library removes @MigratingToGenericEnum.</div><div><br></div><div>Step 4:</div><div>* Clients update library, change usages of "EnumSet<? extends X>" to "EnumSet<X<?>>"</div><div>  and change "EnumSet.allOf(X.class)" to "EnumSet.allOf(X.CONSTANT.getDeclaringClass())"</div><div>* Usages of "EnumSet<X>" now produce compilation errors.</div><div>* Both "EnumSet<? extends X> set = EnumSet.allOf(X.class)" and</div><div>  "EnumSet<X<?>> set = EnumSet.allOf(X.CONSTANT.getDeclaringClass())" compile.</div><div>* Tools should prompt these changes when seeing use of a generic enum with old syntax.</div><div><br></div><div>Step 5 (optional):</div><div>* Library replaces "EnumSet<? extends X>" with "EnumSet<X<?>>" in method parameter types.<br>* Library methods can no longer be called with values of type "EnumSet<? extends X>".<br>* This is source-compatible with clients that have completed step 4.<br>* No further client changes are required.<br>* Casts to EnumSet<X<?>> are no longer required.<br>* This step is optional. The only benefit is removing remaining casts.</div><div>  Libraries can delay this step for as long as desired to allow clients time to complete step 4.</div><div><br></div><div><br></div><div><div>This process is analogous to the gradual transition from a deprecated API to its replacement</div><div>over several major versions. The non-generic syntax becomes "deprecated" at step 1, but</div><div>still compiles, possibly with warnings, until step 4.</div><br></div><div>Cheers,</div><div>Clement </div></div></div>
</div>