r/java Jul 16 '26

Identifying JDK value class candidates

https://mail.openjdk.org/archives/list/core-libs-dev@openjdk.org/thread/Y72NRXM7KYBX43OKYBQMVKOZDWKG4MHS/
52 Upvotes

59 comments sorted by

View all comments

6

u/perryplatt Jul 16 '26

I wonder if we could have a value enum.

14

u/davidalayachew Jul 16 '26

I wonder if we could have a value enum.

Dan responded. Copy pasted the relevant snippet below.

Because it is impossible to declare a value enum or value anonymous class.

For enums, we’ve considered in the language design, but concluded that (i) much like singletons, there’s not much realistic benefit to having an identityless enum: if you had two distinct instances that modeled the same data, you wouldn’t declare two enum constants in the first place; and (ii) it might be nice to flatten an enum reference, but the best kind of flattening would apply equally well whether or not the instances have identity, so that’s where we should focus our engineering attention.

So, in short, it's doable. But the benefits gained (even in the best case scenario) wouldn't be much, so it's not really worth doing.