<div dir="auto"><div>What an excellent explanation, ty vm Chen. No, this clarifies everything for me, ty again.<br><br><div class="gmail_quote gmail_quote_container"><div dir="ltr" class="gmail_attr">On Tue, Sep 23, 2025, 12:13 PM Chen Liang <<a href="mailto:chen.l.liang@oracle.com">chen.l.liang@oracle.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div dir="ltr">
<div style="font-family:"Calibri Light","Helvetica Light",sans-serif;font-size:12pt;color:rgb(0,0,0)">
Hi David,</div>
<div style="font-family:"Calibri Light","Helvetica Light",sans-serif;font-size:12pt;color:rgb(0,0,0)">
In the value objects world, we can think of identity as an extra field on an object that is distinct for every object creation. Due to the uniqueness of this field, we can have shortcuts for hashCode/== that is still compliant but much simpler.</div>
<div style="font-family:"Calibri Light","Helvetica Light",sans-serif;font-size:12pt;color:rgb(0,0,0)">
The proposal to block identity subtypes for abstract value types would be equivalent to blocking subtypes from declaring particular types of fields or implementing particular interfaces (all interfaces are now abstract value, too).</div>
<div style="font-family:"Calibri Light","Helvetica Light",sans-serif;font-size:12pt;color:rgb(0,0,0)">
<br>
</div>
<div style="font-family:"Calibri Light","Helvetica Light",sans-serif;font-size:12pt;color:rgb(0,0,0)">
If you want to ensure safety for abstract value classes, sealed modifier is your friend - they ensure an AVC only has particular subtypes and might be optimized to union types by JVM implementations.</div>
<div style="font-family:"Calibri Light","Helvetica Light",sans-serif;font-size:12pt;color:rgb(0,0,0)">
Otherwise, if a field allows arbitrary value subtypes, they still must be stored as references just like for identity objects. In this case, allowing identity subtypes has little performance impact.</div>
<div style="font-family:"Calibri Light","Helvetica Light",sans-serif;font-size:12pt;color:rgb(0,0,0)">
<br>
</div>
<div style="font-family:"Calibri Light","Helvetica Light",sans-serif;font-size:12pt;color:rgb(0,0,0)">
Regarding the perceived "lack of safety" for identity classes, I would argue it is not associated with identity, but with the mutable fields enabled by identity.</div>
<div style="font-family:"Calibri Light","Helvetica Light",sans-serif;font-size:12pt;color:rgb(0,0,0)">
In fact, in the investigations of heap-flattened value objects and var handles, we find that referring to large value objects as reference pointers is the best way to ensure volatility - because pointers are small enough to be updated atomically.</div>
<div style="font-family:"Calibri Light","Helvetica Light",sans-serif;font-size:12pt;color:rgb(0,0,0)">
<br>
</div>
<div style="font-family:"Calibri Light","Helvetica Light",sans-serif;font-size:12pt;color:rgb(0,0,0)">
Feel free to ask further if you have more overview questions.</div>
<div style="font-family:"Calibri Light","Helvetica Light",sans-serif;font-size:12pt;color:rgb(0,0,0)">
<br>
</div>
<div style="font-family:"Calibri Light","Helvetica Light",sans-serif;font-size:12pt;color:rgb(0,0,0)">
Regards,</div>
<div style="font-family:"Calibri Light","Helvetica Light",sans-serif;font-size:12pt;color:rgb(0,0,0)">
Chen</div>
<div id="m_-7263380536823718272appendonsend"></div>
<hr style="display:inline-block;width:98%">
<div id="m_-7263380536823718272divRplyFwdMsg" dir="ltr"><font face="Calibri, sans-serif" style="font-size:11pt" color="#000000"><b>From:</b> valhalla-dev <<a href="mailto:valhalla-dev-retn@openjdk.org" target="_blank" rel="noreferrer">valhalla-dev-retn@openjdk.org</a>> on behalf of David Alayachew <<a href="mailto:davidalayachew@gmail.com" target="_blank" rel="noreferrer">davidalayachew@gmail.com</a>><br>
<b>Sent:</b> Tuesday, September 23, 2025 8:50 AM<br>
<b>To:</b> Remi Forax <<a href="mailto:forax@univ-mlv.fr" target="_blank" rel="noreferrer">forax@univ-mlv.fr</a>><br>
<b>Cc:</b> valhalla-dev <<a href="mailto:valhalla-dev@openjdk.java.net" target="_blank" rel="noreferrer">valhalla-dev@openjdk.java.net</a>><br>
<b>Subject:</b> Re: Question about Value Classes and inheritance</font>
<div> </div>
</div>
<div>
<div dir="auto">
<div>To answer your question specifically Rémi, I figured this would be useful to prevent things like misuse. For example, the JEP shows how BigInteger can't be a value class due to its internal use of mutability. Well, something like enforcing value classes
might have prevented that. Or maybe not, I am ignorant about that example specifically.</div>
<div dir="auto"><br>
</div>
<div dir="auto">But hopefully you see my point? It feels like there a lot of validation opportunities being left on the table. Value classes aren't just faster, they are safer. So, being able to assert that safety for all child classes seems nice.</div>
<div dir="auto"><br>
</div>
<div dir="auto">Or maybe I am wrong, and Value classes aren't inherently safer. Finality feels safe to me, and finality by default feels safer. Idk.</div>
<div dir="auto"><br>
</div>
<div dir="auto">Truthfully, I'm operating more on feelings here than genuine experience. I'll have something more concrete (or see where I'm wrong) to say once the new EA comes out.<br>
<br>
<div dir="auto">
<div dir="ltr">On Tue, Sep 23, 2025, 8:31 AM Remi Forax <<a href="mailto:forax@univ-mlv.fr" target="_blank" rel="noreferrer">forax@univ-mlv.fr</a>> wrote:<br>
</div>
<blockquote style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div>
<div style="font-family:arial,helvetica,sans-serif;font-size:12pt;color:#000000">
<div><br>
</div>
<div><br>
</div>
<hr id="m_-7263380536823718272x_m_2063411757691996670zwchr">
<div>
<blockquote style="border-left:2px solid #1010ff;margin-left:5px;padding-left:5px;color:#000;font-weight:normal;font-style:normal;text-decoration:none;font-family:Helvetica,Arial,sans-serif;font-size:12pt">
<b>From: </b>"David Alayachew" <<a href="mailto:davidalayachew@gmail.com" rel="noreferrer noreferrer" target="_blank">davidalayachew@gmail.com</a>><br>
<b>To: </b>"valhalla-dev" <<a href="mailto:valhalla-dev@openjdk.java.net" rel="noreferrer noreferrer" target="_blank">valhalla-dev@openjdk.java.net</a>><br>
<b>Sent: </b>Tuesday, September 23, 2025 2:19:40 PM<br>
<b>Subject: </b>Question about Value Classes and inheritance<br>
</blockquote>
</div>
<div>
<blockquote style="border-left:2px solid #1010ff;margin-left:5px;padding-left:5px;color:#000;font-weight:normal;font-style:normal;text-decoration:none;font-family:Helvetica,Arial,sans-serif;font-size:12pt">
<div dir="auto">Hello <span dir="auto"><a href="mailto:valhalla-dev@openjdk.java.net" rel="noreferrer noreferrer" style="color:#15c;text-decoration:underline" target="_blank">@valhalla-dev</a></span>,
<div dir="auto"><br>
</div>
<div dir="auto">I read through JEP 401, and the subsection about subtyping surprised me.</div>
<div dir="auto"><br>
</div>
<div dir="auto">It appears that Abstract Value Classes can permit both Value child classes and Identity child classes. The example of BigInteger helps explain why.</div>
<div dir="auto"><br>
</div>
<div dir="auto">Ok, but there doesn't seem to be any way to say "only value classes can extend me!"</div>
<div dir="auto"><br>
</div>
<div dir="auto">Why is that?</div>
<div dir="auto"><br>
</div>
<div dir="auto">And to be clear, I am not bothered by Abstract Value Classes permitting Identity children, that's fine.</div>
</div>
</blockquote>
<div><br>
</div>
<div>I'm glad this is fine by you because it's important for backward compatibility, it means that you can declare an existing abstract class has "value enable", without requiring sub-classes to be changed.</div>
<div><br>
</div>
<blockquote style="border-left:2px solid #1010ff;margin-left:5px;padding-left:5px;color:#000;font-weight:normal;font-style:normal;text-decoration:none;font-family:Helvetica,Arial,sans-serif;font-size:12pt">
<div dir="auto">
<div dir="auto">I'm moreso confused by lack of ability to say "only value children".</div>
</div>
</blockquote>
<div><br>
</div>
<div>Declaring a class has a value class is really close to be an implementation detail (it mainly depends on if your code abuse of == or not),</div>
<div>so why do you want such ability ?</div>
<div><br>
</div>
<div><br>
</div>
<blockquote style="border-left:2px solid #1010ff;margin-left:5px;padding-left:5px;color:#000;font-weight:normal;font-style:normal;text-decoration:none;font-family:Helvetica,Arial,sans-serif;font-size:12pt">
<div dir="auto">
<div dir="auto"><br>
</div>
<div dir="auto">Thank you for your time and consideration.</div>
<div dir="auto">David Alayachew</div>
</div>
</blockquote>
<div><br>
</div>
<div>regards,</div>
<div>Rémi</div>
<div><br>
</div>
</div>
</div>
</div>
</blockquote>
</div>
</div>
</div>
</div>
</div>
</blockquote></div></div></div>