The following program fails to compile:
```
class Outer1 {
int x;
void m() {
class Outer2 {
int y;
Outer2() {
class Local {
Local(Outer2 Outer2.this) { }
void m() {
int z = x;
}
}
super();
}
}
}
}
```
This uses the obscure "receiver parameter" syntax -- described in JLS 8.4. There's two flavor of the syntax -- one is for regular method declaration and another one (the one in this example) has to do with the "enclosing this" parameter in an inner class constructor.
Turns out that when we are in a local class that is in the prologue of another class, that syntax is unusable -- the above example will fail with:
```
error: cannot reference this before supertype constructor has been called
Local(Outer2 Outer2.this) { }
^
1 error
```
This is a spurious error, which is probably triggered by the fact that javac interpres `Outer.this` as if it was an enclosing this access expression (while this is a simple parameter name).
```
class Outer1 {
int x;
void m() {
class Outer2 {
int y;
Outer2() {
class Local {
Local(Outer2 Outer2.this) { }
void m() {
int z = x;
}
}
super();
}
}
}
}
```
This uses the obscure "receiver parameter" syntax -- described in JLS 8.4. There's two flavor of the syntax -- one is for regular method declaration and another one (the one in this example) has to do with the "enclosing this" parameter in an inner class constructor.
Turns out that when we are in a local class that is in the prologue of another class, that syntax is unusable -- the above example will fail with:
```
error: cannot reference this before supertype constructor has been called
Local(Outer2 Outer2.this) { }
^
1 error
```
This is a spurious error, which is probably triggered by the fact that javac interpres `Outer.this` as if it was an enclosing this access expression (while this is a simple parameter name).
- relates to
-
JDK-8162500 Receiver annotations of inner classes of local classes in static context not found at runtime
-
- In Progress
-