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

Anonymous class capturing two enclosing instances fails to compile

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P4 P4
    • 24
    • 23
    • tools
    • b07

      This program fails to compile:

      class Outer {
          interface A { }
          interface B { }
          
          
          class Inner1 {
              Inner1() {
                  this(new A() {
                      class Inner2 {
                          Inner2() {
                              this(new B() { { m(); g(); } });
                          }

                          Inner2(Object o) { }
                      }

                      void m() { }
                  });
              }

              Inner1(Object o) { }
          }
          void g() { }
      }

      Error is:

      error: no enclosing instance of type Outer is in scope
                              this(new B() { { m(); g(); } });
                                                    ^
      1 error

            mcimadamore Maurizio Cimadamore
            mcimadamore Maurizio Cimadamore
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: