<div dir="ltr">Hi all<br><br>First off, please let me know if I have sent this to the wrong group.<br><br>I'm exploring the JEPs in JDK 21, with the JEP 445 Unnamed Classes and Instance Main Methods I'm getting a compiler error when using instance and static initializers.<br><br>I would like to know if I misunderstood the JEP or if I'm missing something.<br><br>The JEP says:<br><br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><font face="times new roman, serif">"An unnamed class is almost exactly like an explicitly declared class. Its members can have the same modifiers (e.g., private and static) and the modifiers have the same defaults (e.g., package access and instance membership). <b>The class can have static initializers as well as instance initializers.</b> One key difference is that while an unnamed class has a default zero-parameter constructor, it can have no other constructor."</font></blockquote><div><br></div><div>When I try to compile the following code:</div><div><br></div><div><font face="monospace">static {<br>    System.out.println("static initializer");<br>}<br><br>{<br>    System.out.println("instance initializer");<br>}<br><br>void main() {<br>    System.out.println("instance main method");<br>}</font></div><div><br></div><div>I got the following error:</div><div><br></div><div><font face="monospace">UnnamedClassWithInitializers.java:1: error: class, interface, enum, or record expected<br>static {<br>       ^<br>UnnamedClassWithInitializers.java:3: error: class, interface, enum, or record expected<br>}<br>^<br>UnnamedClassWithInitializers.java:7: error: class, interface, enum, or record expected<br>}<br>^<br>UnnamedClassWithInitializers.java:11: error: class, interface, enum, or record expected<br>}<br>^<br>4 errors<br>error: compilation failed</font></div><div><br></div><div>Thank you for your time and work!</div><div><br></div><div>Wesley Egberto<br><br></div></div>