<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class="">
That would be a long way into the future :)
<div class=""><br class="">
</div>
<div class="">Right now, arrays are mutable. So, with respect to value-ness, that’s game over. But let’s say we had immutable arrays (which we surely would like to.). The next hurdle is representing the size in the runtime type system, because, to get flattening,
we cannot be polymorphic in layout. So the JVM would need to understand `final int[3]` as being a different, concrete, type than `final int[4]`. Pushing dependent types into the descriptor and verifier type system is a big lift … <br class="">
<div><br class="">
<blockquote type="cite" class="">
<div class="">On May 19, 2025, at 3:00 PM, John Bossons <<a href="mailto:jbossons@gmail.com" class="">jbossons@gmail.com</a>> wrote:</div>
<br class="Apple-interchange-newline">
<div class="">
<div dir="ltr" class="">Thanks for the clarification.
<div class=""><br class="">
</div>
<div class="">Maybe this is a suggestion for a future JEP (flattening of immutable arrays)? Emphasis on "future".</div>
<div class=""><br class="">
</div>
<div class="">John</div>
</div>
<br class="">
<div class="gmail_quote gmail_quote_container">
<div dir="ltr" class="gmail_attr">On Mon, May 19, 2025 at 2:21 PM Brian Goetz <<a href="mailto:brian.goetz@oracle.com" class="">brian.goetz@oracle.com</a>> wrote:<br class="">
</div>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex">
Arrays are always identity objects; JEP 401 will not change this. PostCodeCA can be flattened into a single object reference, which is still plenty useful but it won’t flatten the underlying array.
<br class="">
<br class="">
> On May 19, 2025, at 2:15 PM, John Bossons <<a href="mailto:jbossons@gmail.com" target="_blank" class="">jbossons@gmail.com</a>> wrote:<br class="">
> <br class="">
> The current version of JEP 401 describes the potential flattening of value object array elements, but leaves unspecified the treatment of value object fields that are themselves (immutable) arrays. Some questions:<br class="">
> <br class="">
> 1) Is a primitive array field (a field that is an array of primitives) necessarily accessed by reference (like an identity object) or can it be accessed as a bit vector (like a scalar primitive)?
<br class="">
> Example (fixed char array length):<br class="">
> value class PostCodeCA {<br class="">
> char[] codeValue; // 6-char code, Ascii letter/number chars, could store as byte[]<br class="">
> PostCodeCA(String s) {<br class="">
> codeValue = s.toCharArray();<br class="">
> // validation code, inter alia checks length == 6<br class="">
> }<br class="">
> ... // Note that array elements are immutable because private<br class="">
> }<br class="">
> Can a PostCodeCA instance be stored as a bit vector, avoiding the indirection of a String reference?<br class="">
> <br class="">
> 2) Can the following be flattened (apart from the inescapable String ref)?<br class="">
> value record AddressCA { String streetAddress, enum provCA, PostCodeCA zipCode }<br class="">
> Note that use of the PostCodeCA class ensures the zipCode value is immutable.<br class="">
> <br class="">
> 3) Does it matter if an array field is of varying length?<br class="">
> Example:<br class="">
> value class CampaignArea {<br class="">
> int areaID;<br class="">
> PostCodeCA[] zipCodes; // varying array length, again immutable because private<br class="">
> CampaignArea(int areaID, List<PostCodeCA> zipCodes) { ... }<br class="">
> ... <br class="">
> }<br class="">
> Does this class definition potentially permit flattening of a CampaignArea instance?<br class="">
> <br class="">
> This isn't just about strings, but they illustrate the issue as well as the potential. Also, it would be useful if this could be clarified in the JEP 401 text.<br class="">
> <br class="">
> John<br class="">
> <br class="">
> -- <br class="">
> Phone: (416) 450-3584 (cell)<br class="">
<br class="">
</blockquote>
</div>
<div class=""><br clear="all" class="">
</div>
<div class=""><br class="">
</div>
<span class="gmail_signature_prefix">-- </span><br class="">
<div dir="ltr" class="gmail_signature">
<div dir="ltr" class="">Phone: (416) 450-3584 (cell)</div>
</div>
</div>
</blockquote>
</div>
<br class="">
</div>
</body>
</html>