开发者社区> 问答> 正文

为什么Java中的方法参数中没有动态绑定?

我想知道为什么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的实例还是其子类的实例,那么为什么不能动态地完成它呢?

展开
收起
垚tutu 2019-12-12 09:29:14 591 0
0 条回答
写回答
取消 提交回答
问答排行榜
最热
最新

相关电子书

更多
Spring Cloud Alibaba - 重新定义 Java Cloud-Native 立即下载
The Reactive Cloud Native Arch 立即下载
JAVA开发手册1.5.0 立即下载