Avoid casting in inherited java-classes

前端 未结 7 1942
执念已碎
执念已碎 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.

提交回复
热议问题