Array fields in value objects
John Bossons
jbossons at gmail.com
Mon May 19 20:23:18 UTC 2025
That's why I encapsulated the char[6] array in the PostCodeCA class. The
immutability is a consequence of the array field being private and final,
so that part should be easy to handle. I don't know how it could easily be
accomplished other than through encapsulation.
With respect to fixing the size, could that be handled by providing an
additional term to the field declaration (e.g. "fixed", as in "fixed
char[6] codeValue", or even by just "char[6]" without the"fixed")? That
would mean the JVM only needs a single tag to know that the field is
special and therefore possible to flatten.
The compiler would need to verify that the field initialization is correct,
but could this not be done by requiring
consistency between the field specification and the array constructor size
parameter -- or for strings requiring use of a new toCharArray(int size)
method? All the compiler needs to do is to check that the
constructor/method parameter matches the field specification. Even if this
were only done for primitives it would be very useful. Could a limited
circumscribed version of this not be done as a "small" lift?
John
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/valhalla-dev/attachments/20250519/c86d6d22/attachment.htm>
More information about the valhalla-dev
mailing list