JDK-8317277 - Java language implementation of value classes and objects

Archie Cobbs archie.cobbs at gmail.com
Wed Oct 18 19:12:21 UTC 2023


Hopefully this is the right place to comment on this ticket:
https://bugs.openjdk.org/browse/JDK-8317277

The one permitted use of the current class instance, implicitly or
> explicitly, is to write to instance fields of the class, either of the form
> 'f = expr' or 'this.f = expr'.
>
> (This deviates from the usual "pre-construction context" rules; TBD
> whether we're expanding the set of permitted actions in a pre-construction
> context (thus permitting field writes before a super() call in *any*
> constructor), or whether we're introducing a slightly different context
> that covers the space between the end of the 'super()' call and the end of
> the constructor execution.)


Allowing assignment of instance fields was discussed as an option for JEP
447, but we said no mainly to take the conservative route i.e., not try to
change too much at once.

If JEP 447 is going to allow pre-construction assignment of instance fields
in value classes and we don't also extend that to identity classes, then it
seems like we'd be creating a worst-of-both-worlds scenario: added
specification & compiler complexity to provide a desirable new feature, but
making it available only some of the time. The result will be developers
having to maintain a more complex mental model in their heads regarding
what rules apply when, and being frustrated by the seeming arbitrariness of
the distinction.

So my vote would be that we allow the assignment of instance fields in
identity classes as well. In theory that could happen in either JEP but
probably JEP 447 makes more sense.

Also, I have a couple of totally unrelated questions about value classes...

1. If v is a value object, what does System.identityHashCode(v) return?
2. If V is a value class, is {Weak,Soft,Phantom}Reference<V> supported?

-Archie

-- 
Archie L. Cobbs
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/valhalla-dev/attachments/20231018/bbfb0f7f/attachment.htm>


More information about the valhalla-dev mailing list