【发布时间】:2010-02-18 07:55:32
【问题描述】:
换句话说,Java 编译器如何确定选择执行哪个重载方法的精确规则是什么?我花了很多时间在谷歌上搜索,但我认为我没有使用正确的搜索关键字。
public class C1 extends C2 {}
public class C2 extends C3 {}
public class C3 {}
public class Test {
public static void main(String[] args) {
C1 c1 = new C1();
// What are the precise rules for determining
// which method below is called?
method(c1, c1);
}
static public void method(C3 test, C3 test2) {
System.out.println("C3");
}
static public void method(C2 test, C3 test2) {
System.out.println("C2");
}
}
【问题讨论】:
标签: java compiler-construction arguments overloading