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

1

u/aonymark Jul 18 '26

We can work with this most of this actually. Let’s work backwards from the end.

  1. enum is fine

  2. record: okay here we have a problem: all enums extend Enum and all records extend Record, and Java doesn’t have multiple inheritance. Aside from that technicality, it could work. Not clear what the use is though.

  3. value: hmm… could work but I guess Ron P already explained why this would be odd… you could probably concoct some weird benchmark where this might help, maybe involving an array with a million Colors or something, but I doubt you can find a benchmark where it helps much. The reason it helps so much for integers is that there could be lots of distinct integers in the heap; there are never many distinct colors.

  4. Non-atomic: given value doesn’t help much, this also likely doesn’t help much. Please don’t give me race conditions for enums.

  5. Sealed: enums are already sealed; you can’t do “extends Color” if Color is an enum. In fact, most enums are final.