In Java, both of those methods are really public static void main(String[] args)
(fundamentally). That's why it won't compile; you can't have a class with two public static void main(String[])
methods.
Java added variadic arguments by having the function compiled as accepting an array, and then by making calls to the function automatically wrap the variadic arguments in an array.
That is, if we have
void foo(String... args)
called with
foo("one", "two", "three");
what the compiler actually creates is
void foo(String[] args)
called with
foo(new String[] { "one", "two", "three"})
(The compiler marks the method in the class file so that it knows later that the array at the end is variadic, but the code it creates is for a method accepting an array.)
This is mostly covered by JLS§8.4.1:
The last formal parameter of a method or constructor is special: it may be a variable arity parameter, indicated by an ellipsis following the type.
...
The declared type of a formal parameter depends on whether it is a variable arity parameter:
If the formal parameter is not a variable arity parameter, then the declared type is denoted by UnannType if no bracket pairs appear in UnannType and VariableDeclaratorId, and specified by §10.2 otherwise.
If the formal parameter is a variable arity parameter, then the declared type is specified by §10.2. (Note that "mixed notation" is not permitted for variable arity parameters.)
...where §10.2 is talking about arrays.
In fact, it's perfectly valid to call a foo(String...)
method with an array instead of discrete arguments. Example, suppose we have:
private static void foo(String... args) {
for (String s : args) {
System.out.println(s);
}
}
we can call that either like this:
foo("one", "two", "three");
or like this
foo(new String[] { "four", "five", "six"});
Both are perfectly valid; example: http://ideone.com/a1Ku37