[英]Is public void main(String[] args) Invalid java main method signature ?
I compiled the following code through notepad 我通过记事本编译了以下代码
class MainClass{
public void main(String args[]){
System.out.println("Hello!");
}
}
I didn't use static keyword and the above code executed, but when I did 我没有使用static关键字,而是执行了上面的代码,但是当我这样做时
javap MainClass
in the command prompt,I got the following output, 在命令提示符下,我得到以下输出,
class MainClass {
MainClass();
public static void main(java.lang.String[]);
}
the keyword was added itself, so is 关键字本身已添加,因此也是如此
public void main(String args[])
also considered a valid signature? 还算有效签名?
As stated in JLS Sec 12.1.4 : 如JLS Sec 12.1.4中所述 :
The method main must be declared
public
,static
, andvoid
.方法main必须声明为
public
,static
和void
。 It must specify a formal parameter (§8.4.1) whose declared type is array ofString
.它必须指定一个声明的类型为
String
数组的形式参数(第8.4.1节)。
I think you might have been looking at an out-of-date version of the class; 我认为您可能一直在查看该课程的过时版本; when I tried decompiling your code,
static
has not been added. 当我尝试反编译您的代码时,尚未添加
static
。
Compiled from "MainClass.java"
class MainClass {
MainClass();
public void main(java.lang.String[]);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.