@ValueClass
, to prepare a class for Valhalla transition (also immediately useful)
#488
Labels
design
An issue that is resolved by making a decision, about whether and how something should work.
new-feature
Adding something entirely new for users, not improving what's there
Milestone
When Valhalla lands, any library class trying to add
value
to its signature is going to face quite a few problems, which it could have addressed (and/or prompted its clients to address their part in) sooner, if the right help had been available.Being able to mark such a class as
@ValueClass
or the like would signify "this class disavows identity", and would enable a set of analyses that could:For most analyzers, a big part of their support would simply be generalizing the checks they already do for Integer and friends, and then just "annotating" those classes with the new
@ValueClass
annotation. As always, they'd be free to act as they see fit, but for purposes of illustration here are some checks we might roughly expect:Validations on the class itself:
synchronized
Object
) also has an explicit@ValueClass
annotationValidations on use sites:
==
identityHashCode
==
(e.g.VarHandle.compareAndSet
)Object
(because it defeats the other validations just mentioned)Note
I'd prefer to see the JDK offer the annotation and the warnings itself. However I think here is still an appropriate place for design discussions, which I hope the JDK folks would participate in and eventually decide whether to uplevel into their own planning.
Edit
This feature also delivers value immediately! These are classes for which identity dependency is already a bug. Protecting against those bugs is a part of the value proposition of Valhalla, but users don't necessarily have to wait for that.
The text was updated successfully, but these errors were encountered: