<!DOCTYPE html><html><head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  </head>
  <body>
    <p>What Archie says - there is going to be a spec clarification and
      associated compiler enhancement to deal with the situation you
      describe.</p>
    <p>Maurizio<br>
    </p>
    <div class="moz-cite-prefix">On 29/10/2024 14:24, Archie Cobbs
      wrote:<br>
    </div>
    <blockquote type="cite" cite="mid:CANSoFxt0c27hRCwBh2Ud+4H2MeCQDD+vm2DZPgqYTfXj2dwG=A@mail.gmail.com">
      
      <div dir="ltr">
        <div dir="ltr">Hi Stephan,<br>
        </div>
        <br>
        <div class="gmail_quote">
          <div dir="ltr" class="gmail_attr">On Tue, Oct 29, 2024 at
            9:11 AM Stephan Herrmann <<a href="mailto:stephan.herrmann@berlin.de" moz-do-not-send="true" class="moz-txt-link-freetext">stephan.herrmann@berlin.de</a>>
            wrote:<br>
          </div>
          <blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Am
            29.10.24 um 14:11 schrieb Olexandr Rotan:<br>
            > Local classes, as well as inner ones (don't confuse
            with nested) implicitly take <br>
            > parents "this" as a constructor argument<br>
            <br>
            They *may* take this argument *if needed*.<br>
            <br>
            But this is more an implementation detail and not the level
            at which the <br>
            specification defines this, is it?<br>
          </blockquote>
          <div><br>
          </div>
          <div>This is a specification thing.</div>
          <div><br>
          </div>
          Here is what is "supposed" to happen: Both "Local" classes in
          the example are declared prior to super(). These classes are
          therefore within an early construction context of "Inner" and
          therefore do not have access to the current instance of
          "Inner" - but this access would be required for the expression
          "s" which is short-hand for "Inner.this.s".</div>
        <div class="gmail_quote"><br>
        </div>
        <div class="gmail_quote">So the reference to "s" should generate
          an error, which happens with the current 24 build:<br>
        </div>
        <div class="gmail_quote"><br>
        </div>
        <div class="gmail_quote"><span style="font-family:monospace">   
            X.java:14: error: cannot reference s before supertype
            constructor has been called<br>
                                                           
            System.out.println(s);<br>
                                                                       
                   ^<br>
          </span></div>
        <div><br>
        </div>
        <div>FYI there is still an <a href="https://github.com/openjdk/jdk/pull/21410" moz-do-not-send="true">outstanding bug and associated PR</a>
          related to this situation, so with the current 24 build you
          also get these (bogus) errors:</div>
        <div><br>
        </div>
        <div><span style="font-family:monospace">    X.java:7: error:
            cannot reference this before supertype constructor has been
            called<br>
                                            new Local() {};<br>
                                                        ^<br>
                X.java:12: error: cannot reference this before supertype
            constructor has been called<br>
                                            new Local() {<br>
                                                        ^</span></div>
        <div><br>
        </div>
        <div>Those errors are bogus, because under the latest "flexible
          constructors" spec, local classes declared in an early
          construction context of class C are treated the same as
          anonymous classes in that situation - they do not have any
          outer instance of type C - so you can declare and instantiate
          them freely.<br>
        </div>
        <div><br>
        </div>
        <div>-Archie<br>
        </div>
        <br>
        <span class="gmail_signature_prefix">-- </span><br>
        <div dir="ltr" class="gmail_signature">Archie L. Cobbs<br>
        </div>
      </div>
    </blockquote>
  </body>
</html>