Question about Value Classes and inheritance

Remi Forax forax at univ-mlv.fr
Tue Sep 23 12:31:24 UTC 2025


> From: "David Alayachew" <davidalayachew at gmail.com>
> To: "valhalla-dev" <valhalla-dev at openjdk.java.net>
> Sent: Tuesday, September 23, 2025 2:19:40 PM
> Subject: Question about Value Classes and inheritance

> Hello [ mailto:valhalla-dev at openjdk.java.net | @valhalla-dev ] ,

> I read through JEP 401, and the subsection about subtyping surprised me.

> It appears that Abstract Value Classes can permit both Value child classes and
> Identity child classes. The example of BigInteger helps explain why.

> Ok, but there doesn't seem to be any way to say "only value classes can extend
> me!"

> Why is that?

> And to be clear, I am not bothered by Abstract Value Classes permitting Identity
> children, that's fine.

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. 

> I'm moreso confused by lack of ability to say "only value children".

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), 
so why do you want such ability ? 

> Thank you for your time and consideration.
> David Alayachew

regards, 
Rémi 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/valhalla-dev/attachments/20250923/a9a77fce/attachment.htm>


More information about the valhalla-dev mailing list