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

Anonymous class capturing two enclosing instances fails to compile

    XMLWordPrintable

Details

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

    Description

      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

      Attachments

        Issue Links

          Activity

            People

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

              Dates

                Created:
                Updated:
                Resolved: