This is my code:
//VariableArguments3.java
public class VariableArguments3
{
static void test(String s,int ...v)
{
System.out.println("length:"+v.length+" String:" +s);
for(int x:v)
System.out.println("x="+x);
}
static void test(String s,double ...d)
{
System.out.println("length:"+d.length+" String:" +s);
for(double x:d)
System.out.println("x="+x);
}
}
and
//VariableArguments3.java
public class VariableArguments3Test
{
public static void main(String args[])
{
VariableArguments3.test("harshal",33,43,34,23,24);
VariableArguments3.test("hosha",43,442);
VariableArguments3.test("hosha",67.7,7.53,73.23);
}
}
i am getting following error:
VariableArguments3Test.java:5: reference to test is ambiguous, both method test(
java.lang.String,int...) in VariableArguments3 and method test(java.lang.String,
double...) in VariableArguments3 match
VariableArguments3.test("harshal",33,43,34,23,24);
^
VariableArguments3Test.java:6: reference to test is ambiguous, both method test(
java.lang.String,int...) in VariableArguments3 and method test(java.lang.String,
double...) in VariableArguments3 match
VariableArguments3.test("hosha",43,442);
^
Now i want to ask that why the VariableArguments3.test("harshal",33,43,34,23,24); and VariableArguments3.test("hosha",43,442); does not transfer the control to static void test(String s,int ...v) in the first file.
Why does it treat static void test(String s,int ...v) and static void test(String s,double ...d) as equal.
Why are the integers passed are treated as equal to double?Shouldn't the integer implicitly convert to double only when method for interger is not specified?