ADDITIONAL SYSTEM INFORMATION :
Linux
A DESCRIPTION OF THE PROBLEM :
Java 22 (and 23) launcher calls default constructor although main() is static.
JEP 463: Implicitly Declared Classes and Instance Main Methods (Second Preview) (Release 22) states:
"In either case, if the chosen method is static then simply invoke it."
REGRESSION : Last worked in version 21.0.2
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
public class HelloWorld {
public HelloWorld() {
System.out.println("HelloWorld()");
}
public static void main() {
System.out.println("Hello World!");
}
}
$ /usr/lib/jvm/java-21-openjdk/bin/javac --release 21 --enable-preview HelloWorld.java && /usr/lib/jvm/java-21-openjdk/bin/java --enable-preview HelloWorld
Hello World!
$ /usr/lib/jvm/java-22-openjdk/bin/javac --release 22 --enable-preview HelloWorld.java && /usr/lib/jvm/java-22-openjdk/bin/java --enable-preview HelloWorld
HelloWorld()
Hello World!
$ /usr/lib/jvm/java-23-openjdk/bin/javac --release 23 --enable-preview HelloWorld.java && /usr/lib/jvm/java-23-openjdk/bin/java --enable-preview HelloWorld
HelloWorld()
Hello World!
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
No constructor should be called.
ACTUAL -
For JDK 22 and 23 the default constructor is called.
---------- BEGIN SOURCE ----------
public class HelloWorld {
public HelloWorld() {
System.out.println("HelloWorld()");
}
public static void main() {
System.out.println("Hello World!");
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
Use static void main(String... args) instead.
FREQUENCY : always