Possible records tweak
forax at univ-mlv.fr
Fri Apr 24 19:32:49 UTC 2020
> De: "Brian Goetz" <brian.goetz at oracle.com>
> À: "Guy Steele" <guy.steele at oracle.com>
> Cc: "amber-spec-experts" <amber-spec-experts at openjdk.java.net>
> Envoyé: Vendredi 24 Avril 2020 21:08:02
> Objet: Re: Possible records tweak
>> Not a bad idea, but here are two and a half alternatives we could consider:
>> (1) Simply ban use of “this” within a compact constructor. This might seem like
>> overkill, but it is very easy to explain: the keyword “this” is not available
>> in a compact constructor, period. Because the argument names shadow the field
>> names, you don’t have access to the fields at all in a compact constructor. If
>> you don’t like it, write a non-compact constructor.
> That's a nice clean way to do it, because under this (heh) model, `this` is
> useless -- can't read the fields (they're DU), can't write them (cause I say
> so), shouldn't call instance methods anyway (because the object is uninitilized
> and therefore may be in an invalid state), and you shouldn't pass `this` to
> alien code (because that undermines the final field guarantees of the JMM.) So
> if its useless, just don't utter it.
It's bold but i like 'this' rule. Easy to explain, easy to remember.
> (Which, in hindsight, might have been a good rule for _all_ constructors, if
> there was another way to initialize the fields. Surely would have eliminated
> much verifier complexity.)
accessing to the identity hashcode or the current class inside a constructor is valid (i believe) but those are a corner cases.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the amber-spec-experts