2 questions about enums and the closed/withdrawn JEP 301

Maurizio Cimadamore maurizio.cimadamore at oracle.com
Wed Mar 29 21:07:20 UTC 2023


On 29/03/2023 19:33, Archie Cobbs wrote:
>         Set<Foo<?>> fooSet = EnumSet.noneOfGeneric(Foo.class);

Of course you can say Set<Foo<?>> - but you can't say EnumSet<Foo<?>>.


> Personally, I would still be happy to have generic enums even without 
> any accomodation by EnumSet/EnumMap.

I hear you - but I believe that EnumSet/Map with their methods are just 
a reminder of what would actually happen should we unleash generic enums 
in the large. There are many API enum-friendly points sedimented over 
the years which use the exact same patterns as EnumSet/Map - all these 
API points will not be usable when working with a generic enum. So, even 
if the JDK might come up with some solution for its own problematic 
classes (and that solution is not even 100% satisfying), there are 
classes outside our control that will just not work with the new enums. 
One rule we try to stick to when adding new features to the Java 
language, is that it should look like they have been there from the 
start. WIth generic enums that's sadly not the case, and worse, they 
create a split between API points that work with them and those which 
don't, which is ultimately bad for the ecosystem.

(That's not to say that generic enums are not useful - I still find many 
useful applications for them...)

Maurizio

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/amber-dev/attachments/20230329/e3e4b660/attachment.htm>


More information about the amber-dev mailing list