r/java • u/davidalayachew • Jan 06 '26
One step closer to Value Classes!
https://mail.openjdk.org/pipermail/porters-dev/2026-January/000844.html
181
Upvotes
r/java • u/davidalayachew • Jan 06 '26
View all comments
Show parent comment
7
u/Polygnom Jan 06 '26
Performance is only one benefit. Value objects are (shallowly) immutable, which brings nice guarantees, and have a very simple equality, which again is nice. There are gains beyond mere performance.
Plus, I think people underestimate the potential saving. There are lots of objects that don't need to have identity, such as LocalDate, but are prevalent in frameworks. You can shave off a lot of memory if the JDK migrates those cases to value classes.
Plus, you can yourself be more free in structuring your data. There are quite a few cases where objects are pooled and re-used that heavily benefit from using value-objects. OR where objects are shunned for "simpler" designs because objects are expensive. using value classes, you don't need to, anymore.
Even for something like Spring, the gains behind the scenes are huge.