Draft Spec for Second Preview of Flexible Constructor Bodies (JEP 482)
Archie Cobbs
archie.cobbs at gmail.com
Thu May 30 22:24:45 UTC 2024
On Thu, May 30, 2024 at 5:08 AM Maurizio Cimadamore <
maurizio.cimadamore at oracle.com> wrote:
> How common is this stuff? This seems to be working today, with some bits
> of javac heroics (some bits of which seem to be working mostly by
> accident). From the perspective of Java developers, wouldn't it be easier
> to say that every class declared in a pre-construction context is static,
> period, and cannot reference anyhing from enclosing contexts? I realize
> this would be an incompatible change, but it seems to me that the status
> quo leaves developers guessing as to whether some code would compile or not.
>
I think doing that would be more surprising. Remember pre-construction
context includes superclass constructor parameters, and developers are
already commonly referring to 2nd enclosing instances in code looking like
this example:
class Outer {
String getName() {
return "fred";
}
class Inner extends Thread {
Inner() {
super(new Runnable() {
@Override
public void run() {
System.out.println("hello from " +
Outer.this.getName());
}
});
}
}
}
-Archie
--
Archie L. Cobbs
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/amber-spec-experts/attachments/20240530/ad132ec0/attachment-0001.htm>
More information about the amber-spec-experts
mailing list