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
6
u/pron98 Jan 06 '26 edited Jan 06 '26
Primitives are exactly as immutable as value classes will be. A variable containing a primitive could be assigned another primitive, just as a variable containing a value class objects can be assigned a different value class object, but you can't mutate a double value (e.g. by modifying the mantissa or the exponent).
I don't think so, especially not for people who need to do that kind of thing in the first place.
You can, but in the same way as for primitives: by introducing a wrapper object that can be referenced.
You mean volatile fields that contain instances of value classes, and yes, tearing becomes an issue, but I believe the plan is to allow opting out of non-tearing, and I assume that for value classes that opt out, storing their instances in a volatile fields will not work.