<div dir="ltr"><div dir="ltr">On Thu, May 30, 2024 at 5:08 AM Maurizio Cimadamore <<a href="mailto:maurizio.cimadamore@oracle.com">maurizio.cimadamore@oracle.com</a>> wrote:</div><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><u></u>
<div>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.<br></div></blockquote><div><br></div><div>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:<br></div><div><span style="font-family:monospace"><br></span></div><div style="margin-left:40px"><span style="font-family:monospace">class Outer {<br> String getName() {<br> return "fred";<br> }<br> class Inner extends Thread {<br> Inner() {<br> super(new Runnable() {<br> @Override<br> public void run() {<br> System.out.println("hello from " + Outer.this.getName());<br> }<br> });<br> }<br> }<br>}</span></div><div><br></div><div>-Archie<br></div></div><br><span class="gmail_signature_prefix">-- </span><br><div dir="ltr" class="gmail_signature">Archie L. Cobbs<br></div></div>