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

Invalid error for early construction local class constructor method reference

    XMLWordPrintable

Details

    • generic
    • generic

    Description

      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);
                       ^

      Attachments

        Issue Links

          Activity

            People

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

              Dates

                Created:
                Updated: