I have a class:
class MyClass {
public MyClass getParent() { ... }
public MyClass[] getChildren() { ... }
....
}
and a subclass
Yes, assuming that you know that the parent and children of a MySubClass
will always be of type MySubClass
.
In that case you could just narrow the return types in MySubClass
and do the casting there:
MySubClass extends MyClass() {
@Overrides
public MySubClass getParent() { return (MySubclass) super.getParent(); }
@Overrides
public MySubClass[] getChildren() { return (MySubclass[]) super.getChildren(); }
public String getId() { }
...
}