Loosening requirements for super() invocation
Archie Cobbs
archie.cobbs at gmail.com
Thu Jan 26 18:07:09 UTC 2023
On Thu, Jan 26, 2023 at 11:25 AM Brian Goetz <brian.goetz at oracle.com> wrote:
> For example, would this be allowed?
>
> class A {
> final int a;
>
> A() { this.a = 0; }
> }
>
> class B extends A {
> B() {
> this.a = 1;
> super();
> }
> }
>
No, that's definitely not supposed to be allowed.
> The current draft JEP says it would:
>
> Add the following restrictions on constructors:
> No access to this, other than assignments to fields, may occur unless
> this is DA
>
>
Thanks for pointing that out. I've updated the draft to say "other than
assignments to local fields".
So, its possible that #3 also has reasonable cost/benefit. The current
> "pinch point" approach could probably be brought to bear on it with
> modifications, without having to thread everything through DA. But I think
> there are subtleties to think through first.
>
I'm hopeful we can include #3 - I think it's important because it gives
users a way to address a problem that is all at once subtle, dangerous, and
difficult to avoid.
-Archie
--
Archie L. Cobbs
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/amber-dev/attachments/20230126/4306f54d/attachment.htm>
More information about the amber-dev
mailing list