-
Bug
-
Resolution: Duplicate
-
P4
-
24
-
jdk-24+5-72-g5c612c230b0
The following example should compile, but does not:
class C1 {
String f1 = "f1";
C1() {
class C2 { // not early for C1
C2() {
class C3 { // early for C2
C3() {
f1.hashCode(); // compiles ok
class C4 { // not early for C3
C4() {
f1.hashCode(); // bogus error
}
}
}
}
super();
}
}
}
}
$ javac -d classes --release 24 --enable-preview C1.java
C1.java:11: error: no enclosing instance of type C1 is in scope
f1.hashCode(); // bogus error
^
Note: C1.java uses preview features of Java SE 24.
Neither reference to "f1" is in the early initialization context of C1, so they should both be allowed.
class C1 {
String f1 = "f1";
C1() {
class C2 { // not early for C1
C2() {
class C3 { // early for C2
C3() {
f1.hashCode(); // compiles ok
class C4 { // not early for C3
C4() {
f1.hashCode(); // bogus error
}
}
}
}
super();
}
}
}
}
$ javac -d classes --release 24 --enable-preview C1.java
C1.java:11: error: no enclosing instance of type C1 is in scope
f1.hashCode(); // bogus error
^
Note: C1.java uses preview features of Java SE 24.
Neither reference to "f1" is in the early initialization context of C1, so they should both be allowed.
- duplicates
-
JDK-8334248 Invalid error for early construction local class constructor method reference
- Resolved