【发布时间】:2016-09-28 20:02:37
【问题描述】:
为什么下面的代码给出编译错误“The method show(Object[]) is ambiguous for the type VarArgs”?。
行显示错误(10,20,30);
public class VarArgs {
public static void main(String[] args) {
show(10,20,30);
}
private static void show(Object... args){
System.out.println("Object");
}
private static void show(int... arry){
System.out.println("Integer");
}
}
JDK:jdk1.6.0_23
【问题讨论】:
-
谢谢图纳基。不确定它是否重复,因为重载是 int vararg 和 Integer vaarg。制作 show(10,20,30) 时,为什么会出现混乱?另一方面 private static void show(Integer... arry) 有效..