Possible records tweak
john.r.rose at oracle.com
Fri Apr 24 19:04:36 UTC 2020
On Apr 24, 2020, at 11:24 AM, Brian Goetz <brian.goetz at oracle.com> wrote:
> the question I want to ask is: should we simply _ban_ reads and writes to `this.x` in the body of a compact constructor, and let the auto mechanism take care of it, so there is no confusion about mixing initialization modes, the correct idiom, or reading possibly uninitialized fields
If we can get away with it, yes^100.
Assigning to a final field is one of the darkest corners of the language.
In Java 1.1 we had to create a jungle of DA/DU rules for those assignments.
It would be great if they just went away, for compact constructors.
When reading the first 1/2 of your message, I was partly afraid the ask was
going to be, “drop the auto-initialize feature” on the grounds of user
confusion. One of our hardest problems historically is to reduce the
user confusion, and *still* have our nice things.
I also like Guy’s doubling down on the solution which forbids `this`
in the body of the constructor.
Any of these restrictions can be lifted in a future version of the language,
so it’s relatively safe to make them now.
More information about the amber-spec-experts