我有以下类(class)。
public class Test {
public static void main(Integer[] args) {
System.out.println("This is not a main");
}
public static void main(String[] args) {
System.out.println("This is the main");
}
}
这里有两个 main
方法,它们接受 Integer[]
和 String[]
作为输入参数。我的问题是 JVM
如何始终加载第二个方法作为此类的主要方法。为什么总是将输入参数视为 String
的 array
?
最佳答案
因为这是 Java 一直在寻找的东西。 Java Language Specification, Section 12.1.4 :
The method main must be declared public, static, and void. It must specify a formal parameter (§8.4.1) whose declared type is array of String
关于java - 具有不同签名的两种主要方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18194793/