Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8336770

Anonymous classes based on inner local classes are restricted in pre-construction

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P3 P3
    • None
    • 24
    • tools

      static class Test {
          Test() {}

          Test(int a) {
              class InnerLocal {} //compilation succeeds
              new InnerLocal() {}; //compilation fails here
              new Object() {}; //compilation succeeds
              new InnerLocal(); //compilation succeeds here
              this();
          }
      }
       

      With JDK24b5:
      /Main.java:6: error: cannot reference this before supertype constructor has been called
              new InnerLocal() {}; //compilation fails here

      The same code compiles if put in static context:

      static void test(int a) {
          class InnerLocal {}
          new InnerLocal() {}; //no compilation error
      }
       
      The specification is murky in this area, however, as per email discussion, the code should compile.

            vromero Vicente Arturo Romero Zaldivar
            eananeva Ella Ananeva
            Votes:
            1 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: