Value class with fields mutable as non default
Julian Waters
tanksherman27 at gmail.com
Fri Mar 11 09:07:25 UTC 2022
Hey Andersen,
I agree with you, my naive understanding is that since value classes are
ultimately still reference types, mutability of their fields may not be
impossible, even though they no longer have any identity, since the values
of the fields themselves can still be accessed through the reference. It
shouldn't matter if we have exploded a value object into its component
fields and reconstructed it elsewhere, since modifications would simply
affect the reconstructed object instead of the original one. Having value
classes with state that can be modified would present much flexibility to
developers working with value classes, in my view. Not sure about the
default immutability though, but I'll leave that up for discussion.
On a related note, I'm also about to propose the ability to declare any
object as a value when it's being constructed, instead of only at the class
definition, since the former would require explicit ahead of time knowledge
that a specific class would benefit from being value based, while the
latter would provide more flexibility.
Have a great day!
best regards,
Julian
More information about the valhalla-dev
mailing list