Why don't enums allow generics since Java 5? (was "Re: 2 questions about enums and the closed/withdrawn JEP 301")

David Alayachew davidalayachew at gmail.com
Wed Mar 29 19:08:21 UTC 2023


Hello Brian,

Thank you for the response!

> My assumption is (a) that they were
> being co-developed and so they were
> focused on the compilation substrate
> they could count on, and (b) it's just
> impractically difficult to think ten steps
> ahead.

Makes a lot of sense, ty.

> Enums as they were done in Java 5 were
> already many steps ahead of enums in
> other languages of the day; enums in C
> were just aliases for ints, nothing more,
> whereas Java's enums were full blown
> objects with state and could implement
> interfaces, with constant-specific
> behavior.  When you're this many steps
> ahead of where the rest of the world is,
> it's hard to see more steps ahead; it's only
> after using them for a decade that the
> limitations start to chafe.

Amen.

Enums are my all-time favorite feature in Java for exactly these reasons,
plus the lightning performance of EnumSet and EnumMap (using a bit set
instead of hashing to model set inclusion was a stroke of genius imo). It
was actually java enums that made me not only become a dedicated Java
programmer, but it made this language my favorite over them all, even today.

Even now, the only languages that I know of that have better enums (not
abstract data types, enums, as in enumerated VALUES) are languages that are
also on the JVM. In which case, I consider that further praise for Java's
step forward on enums, since they are building off of it.

Yes, it was a gigantic step above the rest of the world at the time, so it
makes sense how it might not have been prioritized.

> Similarly, the issues Maurizio raised
> about weaknesses in the generic type
> system were surely known at the time,
> and were probably dismissed as "glass
> .1% empty" (and reasonably so, at the
> time, given the scope and ambitiousness
> of the generics effort.)  Again, only
> decades later does our perspective on
> "no one really needs that" start to shift.

This also makes a lot of sense. That's a hard tradeoff to balance, not to
mention the amount of crystal ball searching you have to do to imagine what
the future needs might be, not just now.

Thank you for the help and insight!
David Alayachew
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/amber-dev/attachments/20230329/69740913/attachment.htm>


More information about the amber-dev mailing list