我想知道为什么 Java 中的方法参数中没有动态绑定?例子:
static class C {
public static void test(C c) {
System.out.println("C");
}
}
static class D extends C {
public static void test(D d) {
System.out.println("D");
}
}
public static void main(String[] args) {
C c = new D();
D d = new D();
test(c);
无论如何都必须确定,变量c是包含类C的实例还是它的子类的实例,为什么不能动态完成呢?