[lworld] setAccessible change and VarHandle test update

John Rose john.r.rose at oracle.com
Sat Mar 10 01:07:46 UTC 2018


On Mar 8, 2018, at 2:55 PM, Paul Sandoz <paul.sandoz at oracle.com> wrote:
> 
> 
>> On Mar 8, 2018, at 2:46 PM, Karen Kinnear <karen.kinnear at oracle.com> wrote:
>> 
>> Should unsafe also not be allowed to write to them - so final is final?

I think the "final means final" discussion applies only to objects
with identity and at least the potential of a changeable state
A value has no identity, and no way to express a change in
state.  Attempting to change the state of a value (e.g., by
updating a field) must *always* result in a new value,
not somehow "the old value but with a different value".

Thus, Field.set is an impossible operation for a field of
a value type.  Not an inaccessible or unsafe or unwise
operation, an impossible one.

(This is the deep reason we can and should move ourselves
away from using "final" as a modifier for fields in value classes:
The word "final" doesn't mean what you think it means there.
It's not just that you are not allowed to assign to it; it is that
it intrinsically cannot change without changing the enclosing
value along with it.)

A new operation Field.with or Field.update could make
sense for values, but the access control rules for it are
not yet clear.

Bottom line:  Field.set must not "do something" on value class
fields (fields of any type: ref/prim/val), under any circumstances
(final or not, setAccessible or not).

— John


More information about the valhalla-dev mailing list