How are these append()
methods ambiguous?
public class Try_MultipleArguments {
public static void main(String[] args) {
int array1[] = new int[] {1, 2, 3};
int array2[] = new int[] {4, 5, 6};
append(array1, array2);
append(array1, 4, 5, 6);
}
public static int[] append(int[] array1, int[] array2) {
int[] ans = new int[array1.length + array2.length];
for(int i=0; i<array1.length; ++i) {
ans[i] = array1[i];
}
for(int i=0; i<array2.length; ++i) {
ans[i+array1.length] = array2[i];
}
return ans;
}
public static int[] append(int[] array1, int ... array2) {
return append(array1,array2);
}
}
UPDATE
Varargs is equivalent to an array, but this is from inside of the method. From outside of the method it should not be equivalent to it.
UPDATE 2
I see now that I can pass an array to vararg. I didn't knew that. Was always workarounding this need. Hmmm.... Was this from the very beginning of java varargs?