任何人都可以请解释为什么这段代码会引发一个模糊的过载错误,当然整数方法更具体和适用?Var-args overloading
感谢,
斯内德
package object_orientation;
public class Ambiguous {
//ambiguous error compiler unsure whether boxing is needed or not
static void overload(Integer... d){
System.out.println("Integer");
}
static void overload(long... d){
System.out.println("Long");
}
public static void main(String a[]){
int i = 1;
overload(i);
}
}
看到“整数”与“int”不同。 Integer是一个包装。 – fpe
好帖子在此 - http://stackoverflow.com/questions/2521293/bug-with-varargs-and-overloading –
如果你在你的重载方法中将'long ...'更改为'long',它将会被编译。我相信可变参数在编译时转换为数组,所以我认为这就是模糊发生的地方 –