Unnamed Classes with Initializers

David Alayachew davidalayachew at gmail.com
Tue Jul 4 01:04:17 UTC 2023


Hello Wesley,

Thank you for reaching out!

I can reproduce your error.

Here are my error logs for context.

~~~

$ java --enable-preview --source 21 abc.java
abc.java:5: error: class, interface, enum, or record expected
static {
       ^
abc.java:7: error: class, interface, enum, or record expected
}
^
abc.java:11: error: class, interface, enum, or record expected
}
^
Note: abc.java uses preview features of Java SE 21.
Note: Recompile with -Xlint:preview for details.
3 errors
error: compilation failed

$ cat abc.java
void main() {
        System.out.println("Main");
}

static {
System.out.println("Static");
}

{
System.out.println("Instance");
}

$ java --version
openjdk 21-ea 2023-09-19
OpenJDK Runtime Environment (build 21-ea+29-2411)
OpenJDK 64-Bit Server VM (build 21-ea+29-2411, mixed mode, sharing)

$ javac --version
javac 21-ea

Thank you for your time and help!
David Alayachew
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/amber-dev/attachments/20230703/37d6a054/attachment-0001.htm>


More information about the amber-dev mailing list