This expression in lambda in early construction context
Ella Ananeva
ella.ananeva at oracle.com
Wed Jun 5 18:45:57 UTC 2024
Hi,
I understand that JEP 482 allows to refer to this in the early construction context if this expression is in the left part of an assignment expression:
class Test {
int a;
Test() {
this.a = 1;
super();
}
}
This compiles just fine (I have JDK 23 build 25).
However, when I try to do the same in a lambda body, I get a compilation error:
interface Foo {
void foo();
}
class Test {
int a;
Test() {
Foo lmb = () -> { this.a = 1;};
super();
}
}
Test.java:9:27
java: cannot reference this before supertype constructor has been called
Is lambda body some special case?
Thank you,
Ella Ananeva
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/amber-dev/attachments/20240605/4a0a29c2/attachment-0001.htm>
More information about the amber-dev
mailing list