<div dir="ltr"><div dir="ltr">On Wed, Mar 29, 2023 at 12:53 PM Maurizio Cimadamore <<a href="mailto:maurizio.cimadamore@oracle.com">maurizio.cimadamore@oracle.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>
    <div>The following is
        legal:
      <pre style="font-family:Consolas,Inconsolata,Courier,monospace;font-size:1em;line-height:1.2em;margin:1.2em 0px"><code style="font-size:0.85em;font-family:Consolas,Inconsolata,Courier,monospace;margin:0px 0.15em;background-color:rgb(248,248,248);white-space:pre-wrap;overflow:auto;border-radius:3px;border:1px solid rgb(204,204,204);padding:0.5em 0.7em;display:block">Box<? extends Foo>
</code></pre>
      <p style="margin:0px 0px 1.2em">But that is also a
        type that has significantly different characteristics from the
        ones above - e.g. you can’t call <code style="font-size:0.85em;font-family:Consolas,Inconsolata,Courier,monospace;margin:0px 0.15em;padding:0px 0.3em;white-space:pre-wrap;border:1px solid rgb(234,234,234);background-color:rgb(248,248,248);border-radius:3px;display:inline">Box::set</code>
        on it. So, even before getting to generic methods accepting
        Foos, we have a much more fundamental problem: we can't even
        express the type of a variable of type <code style="font-size:0.85em;font-family:Consolas,Inconsolata,Courier,monospace;margin:0px 0.15em;padding:0px 0.3em;white-space:pre-wrap;border:1px solid rgb(234,234,234);background-color:rgb(248,248,248);border-radius:3px;display:inline">Box<Foo></code>
        in the type-system (!!).<br></p></div></div></blockquote><div>Thanks Maurizio...  and of course if I had actually tried what I was suggesting I would have seen the problem... !<br><br>You *can* come close though... you just have to pay for your offense with <span style="font-family:monospace">@SuppressWarnings("unchecked")</span>:<br><br><div style="margin-left:40px"><span style="font-family:monospace">import java.util.*;</span><br><span style="font-family:monospace">public class GenericEnum {</span><br><span style="font-family:monospace"></span><br><span style="font-family:monospace">    public static class Enum<T extends Enum<T>> {</span><br><span style="font-family:monospace">    }</span><br><span style="font-family:monospace"></span><br><span style="font-family:monospace">    public static class Foo<S> extends Enum<Foo<S>> {</span><br><span style="font-family:monospace">    }</span><br><span style="font-family:monospace"></span><br><span style="font-family:monospace">    public abstract static class EnumSet<T extends Enum<T>> implements Set<T> {</span><br><span style="font-family:monospace"></span><br><span style="font-family:monospace">        public static <T extends Enum<T>> EnumSet<T> noneOfGeneric(Class<? extends T> c) {</span><br><span style="font-family:monospace">            return null;</span><br><span style="font-family:monospace">        }</span><br><span style="font-family:monospace">    }</span><br><span style="font-family:monospace"></span><br><span style="font-family:monospace">    @SuppressWarnings("unchecked")   // this is still necessary, too bad</span><br><span style="font-family:monospace">    public static void main(String[] args) {</span><br><span style="font-family:monospace">        Set<Foo<?>> fooSet = EnumSet.noneOfGeneric(Foo.class);</span><br><span style="font-family:monospace">    }</span><br><span style="font-family:monospace">}</span><br></div><br>Personally, I would still be happy to have generic enums even without any accomodation by EnumSet/EnumMap.<br></div><div><br></div><div>Then all I would have to homebrew would be a few wrapper methods around the EnumSet/EnumMap factory methods :)<br></div><div><br>-Archie<br></div></div><br><span class="gmail_signature_prefix">-- </span><br><div dir="ltr" class="gmail_signature">Archie L. Cobbs<br></div></div>