r/java • u/mehdi-ware • Oct 30 '20
JEP 301: Enhanced Enums is Withdrawn
After conducting some real world experiments using the feature described in this JEP it became apparent [1] that generic enums don't play well with generic methods. The issues are especially evident when considering static generic methods accepting a Class<X> parameter, where X models an enum type, many of which are defined in the Java SE API itself, like EnumSet::allOf, EnumSet::noneOf. In such cases, passing a class literal corresponding to a generic enum as a paramater would result in a compile-time error --- because of a failure in generic type well-formedness. A proposal attempting to rectify these issues was later formulated and discussed [2], but was also found lacking, as it essentially amounted at promoting the use of more raw types, and, more broadly, raised concerns regarding the return on complexity associated with the enhanced-enums feature. For these reasons, we are now withdrawing this JEP.
89
u/GhostBond Oct 30 '20
In software there's a lot of good ideas at first, that turn out to not work when you dig into actually using them.
Its good to hear someone is considering that, rather than just throwing it into the language making it a mess, just so they don't have to admit it.
Trying out new things then realizing some of them aren't going to work is literally our jobs as software developers.
15
u/nlisker Oct 30 '20
I was really looking forwards to this one. Generic enums have so many uses that people don't even realize that they are modeling around this limitation. :(
4
u/nlisker Oct 30 '20
Link to the JEP: https://openjdk.java.net/jeps/301
3
u/s888marks Oct 31 '20
Additional information about the problems encountered by this JEP are in this email from Maurizio Cimadamore:
http://mail.openjdk.java.net/pipermail/amber-spec-experts/2017-May/000041.html
2
u/UnspeakableEvil Oct 31 '20
Shame, but good to hear the reasons. On a personal positive note, TIL about EnumSet, I've always just used a HashSet and never thought twice about it!
2
u/jonhanson Oct 31 '20 edited Mar 07 '25
chronophobia ephemeral lysergic metempsychosis peremptory quantifiable retributive zenith
3
u/UnexpectedLizard Oct 30 '20
In my decade of experience, I've never had a coworker use an enum, and I almost never find them in libraries either.
Are enums an anti-pattern that make code more confusing? Why don't people use them more?
1
u/Jonjolt Oct 30 '20
Welp, just when you think something seems like it would be easy it also looks different than what I thought it would be I thought the goal was more like this:
enum MyEnum implements Function<String, X> {-6
u/gas3872 Oct 31 '20 edited Oct 31 '20
Sorry, what is a failure of generic type well formedness. The first link asks for login password, the second one i scrolled through and could not find it.
As a side note, i think you should not use enums except for values. Never saw a good code that has heavy enums (with methods etc) in it. Its either used to implement tagged classes antipattern. Or the enum itself becomes a poorly made hierarchy (with a lot of boilerplate inside), because people dont realize that what they actually do create class hiererchy under the hood. Another problem is that people learn about enums (i also blame effective java book for that) and immediately try to write enum everywhere without understanding whats happening. But on the other hand if they were not using enums but the normal classes, it would ve been clear what they are doing and what are the problems to be solved.
Enums are fine when you hold a simple value. In fact the resulting java bytecode is the same as if you use static field. But i think its where enums should have stopped, because of the things i mentioned above.
-28
u/_INTER_ Oct 30 '20
weak, so weak