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
?
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
Because Strings are what you're passing into the command line.
the 45
from
myProgram.exe 45
is not an integer. it is a string containing the characters 4
and 5
It just so happens that you can use a string like "45"
to represent an integer. It's a little more difficult to do it the other way around.(for the user at least)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With