I have the following simple hello world in Java:
class A {
static {
System.out.println("Hello world");
}
}
It works as expected, but oddly, it gives an error saying that the main method doesn't exist after.
$ javac A.java && java A
Hello world
Exception in thread "main" java.lang.NoSuchMethodError: main
Why? Should I ignore it? I even tried making a method called "main", but it changes nothing.
class A {
static {
main();
}
public static void main() {
System.out.println("Hello world");
}
}
$ javac A.java && java A
Hello world
Exception in thread "main" java.lang.NoSuchMethodError: main
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…