Avoid casting in inherited java-classes

前端 未结 7 1955
执念已碎
执念已碎 2021-02-14 17:56

I have a class:

class MyClass {

  public MyClass getParent() { ... }

  public MyClass[] getChildren() { ... }

  ....

}

and a subclass

相关标签:
7条回答
  • 2021-02-14 18:41

    Is there any way (by language or design) to avoid that casting?

    The answer is No. If you want to access super class field or method than you must explicitly cast.

    0 讨论(0)
提交回复
热议问题