<p dir="ltr">Local classes, as well as inner ones (don't confuse with nested) implicitly take parents "this" as a constructor argument (if I'm not mistaken, untill some point of time or even now inner classes were elevated to top level classes with reference to parent as their constructor argument).</p>
<p dir="ltr">In fact, if I remember correctly, the behaviour in version 23 is a known bug that was fixed a while ago</p>
<br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Tue, Oct 29, 2024, 15:02 Stephan Herrmann <<a href="mailto:stephan.herrmann@berlin.de">stephan.herrmann@berlin.de</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Given:<br>
<br>
public class X {<br>
        public static void main(String[] argv) {<br>
                class Inner {<br>
                        String s;<br>
                        Inner() {<br>
                                class Local {}<br>
                                new Local() {};<br>
                                super();<br>
                        }<br>
                        Inner(int i) {<br>
                                class Local {}<br>
                                new Local() {<br>
                                        void m() {<br>
                                                System.out.println(s);<br>
                                        }<br>
                                };<br>
                                super();<br>
                        }<br>
                }<br>
                new Inner();<br>
        }<br>
}<br>
<br>
javac 23 reports exactly one error against the illegal use of 's' in Inner(int). <br>
Good.<br>
<br>
javac 24 ea+21 additionally flags both instantiations "new Local() ...":<br>
<br>
X.java:7: error: cannot reference this before supertype constructor has been called<br>
                                 new Local() {};<br>
                                             ^<br>
<br>
I don't see any reason for that error as I don't see any access to 'this'. What <br>
is the reason for this change in behavior?<br>
<br>
thanks,<br>
Stephan<br>
</blockquote></div>