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

JEP 482 Spec disallows qualified this in early construction context

XMLWordPrintable

    • Icon: Task Task
    • Resolution: Fixed
    • Icon: P4 P4
    • 24
    • None
    • tools
    • master

      JEP 482 spec states that

      It is a compile-time error if a qualified `this` expression occurs in an
      early construction context ([8.8.7.1]) of the class named by *TypeName*.

      However, this code compiles with JDK-23 b 25:

      static class Test {
          int a;
          Test() {}

          Test(int a) {
              Test.this.a = 1;
              this();
          }
      }

          public static void main(String argv[]) {
              Test test = new Test(1);
          }

      Per email discussion, the compiler implements a more sophisticated treatment of qualified this, thus the discrepancy. The specification should address this change.

            gbierman Gavin Bierman
            eananeva Ella Ananeva
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: