Why don't enums allow generics since Java 5? (was "Re: 2 questions about enums and the closed/withdrawn JEP 301")
Brian Goetz
brian.goetz at oracle.com
Wed Mar 29 18:51:02 UTC 2023
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. 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.
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.
> Why were enums never given generics in the first place? I know they
> came out in the same release, so theoretically, that was the best time
> possible to bake this feature in and ensure it played well from the
> beginning. Why didn't they?
More information about the amber-dev
mailing list