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

Invalid error for early construction local class constructor method reference

XMLWordPrintable

    • b25
    • generic
    • generic

      The new "flexible constructors" JEP specifies that a local class declared in an early construction context does not have an immediate outer instance, i.e., same behavior as an anonymous class in that situation.

      However, the compiler still (incorrectly) tries to verify one in the case of a method reference to the local class' constructor.

      Example:

          import java.util.function.Supplier;
          class EarlyLocalCtorRef {
              EarlyLocalCtorRef(int x) {
                  class InnerLocal { }
                  this(InnerLocal::new);
              }
              EarlyLocalCtorRef(Supplier<Object> s) {
              }
          }

      Expected output:

          Successful compilation.

      Actual output:

          EarlyLocalCtorRef.java:5: error: cannot reference this before supertype constructor has been called
                  this(InnerLocal::new);
                       ^

            mcimadamore Maurizio Cimadamore
            acobbs Archie Cobbs
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: