Search code examples
javaprogram-entry-point

Two Main methods with different signatures


I have following 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"); 
    }
}

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?


Solution

  • Because that's what Java always looks for. 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