【发布时间】:2012-12-27 11:02:28
【问题描述】:
案例 1
static void call(Integer i) {
System.out.println("hi" + i);
}
static void call(int i) {
System.out.println("hello" + i);
}
public static void main(String... args) {
call(10);
}
案例 1 的输出:hello10
案例 2
static void call(Integer... i) {
System.out.println("hi" + i);
}
static void call(int... i) {
System.out.println("hello" + i);
}
public static void main(String... args) {
call(10);
}
显示编译错误reference to call ambiguous。但是,我无法理解。为什么 ?但是,当我从Case 2 中注释掉任何call() 方法时,它工作正常。谁能帮我理解,这里发生了什么?
【问题讨论】:
-
你认为应该调用什么方法 - 为了使情况不模棱两可?
-
call(int... i),因为它更具体。
标签: java methods polymorphism java-7 boxing