两种具有不同签名的主要方法 [英] Two Main methods with different signatures

查看:90
本文介绍了两种具有不同签名的主要方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下课程.

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如何始终将第二个方法加载为此类的主要方法.为什么总是将输入参数视为Stringarray?

In here there are two main method which are accept Integer[] and String [] as input argument. My question is how JVM always load second method as main method of this class. Why always consider input argument as array of String?

推荐答案

因为这就是Java一直在寻找的东西. Java语言规范,第12.1节. 4 :

Because that's what Java always looks for. Java Language Specification, Section 12.1.4:

方法main必须声明为public,static和void.它必须指定一个声明的类型为String数组的形式参数(第8.4.1节)

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

这篇关于两种具有不同签名的主要方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆