JEP 492: javac error on a valid code
Ekaterina Semenova
ekaterina.semenova at jetbrains.com
Mon Feb 10 14:30:14 UTC 2025
Dear Experts,
I noticed that javac throws a compilation error on the following code using
a Java 24 preview feature (JEP 492 (flexible constructor body) :
```
class Outer { private int i; class Sub extends Outer { Sub() { i = 42; //
javac error: java: cannot reference i before supertype constructor has been
called super(); } } }
```
I would expect though the code to be compilable because in this case i
should refer to the containing class private field, not to the superclass
field (because it is private thus inaccessible to the subclass), so it
should be allowed to reference it in the constructor prologue.
Could you please take a look?
Thank you,
Ekaterina
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/amber-dev/attachments/20250210/b78c28c2/attachment.htm>
More information about the amber-dev
mailing list