I came across the same code:
public class Devk{
public static void tMeth(Integer... i){
System.out.print("A");
}
public static void tMeth(int... i){
System.out.print("B");
}
public static void main(String args[]){
tMeth(Integer.valueOf("7"));
tMeth(new int[2]);
tMeth(new Integer[2]);
}
}
after the call, I see
java: reference to tMeth is ambiguous, both method tMeth(java.lang.Integer...) in GenericsTest.Test1 and method tMeth(int...) in GenericsTest.Test1 match
The method Integer.valueOf("7")returns an integer shell. I expect to see Ain the console.
Who can explain this behavior and provide a general rule for this?
PS
public static void tMeth(Integer i){
System.out.print("A");
}
public static void tMeth(int i){
System.out.print("B");
}
public static void main(String args[]){
tMeth(1);
tMeth(new Integer(1));
}
source
share