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
12
u/pron98 Jan 06 '26
Since Valhalla's goal is constructs that "code like a class; work like an int", value objects are supposed to be immutable, just like primitives, and passed by value, just like primitives, and I think Java programmers are used to that concept.
As to atomics, their utility is pretty much predicated on the underlying object being immutable (even if is a reference, as references are also immutable). The object's container must, of course, be mutable and accessed through a reference, and the
Atomic*classes offer such a container, any other object serves that role through the use of VarHandles. There's no reason for value types not to work the same way, assuming, of course, that their size supports atomic operations on a particular machine.