Test.java:12: reference to go is ambiguous, both method go(int...) in Test and method go(java.lang.Integer...) in Test match
Test.java:13: reference to go is ambiguous, both method go(int...) in Test and method go(java.lang.Integer...) in Test match
Question 1: is there any possibility to get a call to one of the go() methods compiled?
Question 2: if the answer to question 1 is "no", why does the compiler complains about accessing the methods an not about defining the to go() methods?
The only way to get a successful call is to do this:
The reason why the original invocations are ambiguous is because they involve the varargs mechanism, and both methods are possible matches. When an invocation matches more than one method in which the varargs mechanism needs to be used (and no other method in which the varargs mechanism isn't used is a match,) the invocation is considered ambiguous by the compiler.
And to clarify: If you pass an array which can directly be matched to the varargs array, you are not involving the varargs mechanism.
All code in my posts, unless a source is explicitly mentioned, is my own.
Seriously? That's what you're going with? I prefer this tiny ad: