1.Why ambiguous error occure ?
This part has been already answer by other user, nicely.
Why varargs must be declared last ?
Well this is how JAVA is written. The reasonable explanation i can think of is keeping the usual read direction of the parenthesis ()
which has Associativity: left-to-right, If we are to declare a function like:
public void aFunc(String... args, String x, String y, String z)
If we invoke this function with exactly three arguments:aFunc("arg1", "arg2", "arg3")
: Then we have a decision problem: which variable should belong to variable arity parameter args
? To know the answer we will have to go from right-to-left, just reverse of the usual order of the parenthesis ()
associativity.