-
Bug
-
Resolution: Duplicate
-
P3
-
None
-
24
static class Test {
Test() {}
Test(int a) {
class InnerLocal {} //compilation succeeds
new InnerLocal() {}; //compilation fails here
new Object() {}; //compilation succeeds
new InnerLocal(); //compilation succeeds here
this();
}
}
With JDK24b5:
/Main.java:6: error: cannot reference this before supertype constructor has been called
new InnerLocal() {}; //compilation fails here
The same code compiles if put in static context:
static void test(int a) {
class InnerLocal {}
new InnerLocal() {}; //no compilation error
}
The specification is murky in this area, however, as per email discussion, the code should compile.
Test() {}
Test(int a) {
class InnerLocal {} //compilation succeeds
new InnerLocal() {}; //compilation fails here
new Object() {}; //compilation succeeds
new InnerLocal(); //compilation succeeds here
this();
}
}
With JDK24b5:
/Main.java:6: error: cannot reference this before supertype constructor has been called
new InnerLocal() {}; //compilation fails here
The same code compiles if put in static context:
static void test(int a) {
class InnerLocal {}
new InnerLocal() {}; //no compilation error
}
The specification is murky in this area, however, as per email discussion, the code should compile.
- duplicates
-
JDK-8334248 Invalid error for early construction local class constructor method reference
-
- Resolved
-