<div dir="ltr"><div>Dear Experts,<br><br></div>I noticed that javac throws a compilation error on the following code using a Java 24 preview feature (JEP 492 (flexible constructor body) :<br><div><span style="color:rgb(29,28,29);font-family:Monaco,Menlo,Consolas,"Courier New",monospace;font-size:12px;font-variant-ligatures:none;background-color:rgba(29,28,29,0.04)"><br></span></div><div><span style="color:rgb(29,28,29);font-family:Monaco,Menlo,Consolas,"Courier New",monospace;font-size:12px;font-variant-ligatures:none;background-color:rgba(29,28,29,0.04)">```</span></div><div><span style="color:rgb(29,28,29);font-family:Monaco,Menlo,Consolas,"Courier New",monospace;font-size:12px;font-variant-ligatures:none;background-color:rgba(29,28,29,0.04)">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();
}
}
}</span><br><div>```</div><div><br></div><div>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. </div><div>Could you please take a look?</div></div><div><br></div><div>Thank you, </div><div>Ekaterina</div></div>