-
Bug
-
Resolution: Fixed
-
P4
-
None
-
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);
^
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);
^
- duplicates
-
JDK-8336255 Invalid compiler error with early reference in nested class
-
- Closed
-
-
JDK-8322882 Null pointer error when compiling Static initializer in a local class
-
- Resolved
-
-
JDK-8336770 Anonymous classes based on inner local classes are restricted in pre-construction
-
- Closed
-
- links to
-
Commit(master) openjdk/jdk/5b9932f8
-
Review openjdk/jdk/19705
-
Review(master) openjdk/jdk/19904
-
Review(master) openjdk/jdk/21410
(2 links to)