I have a MyClass which has an attribute of type MyAttribute. This class is inherited by MySubClass which has an attribute of type MySubAttribute. MySubAttribute is a subclass of MyAttribute :
class MyClass {
MyAttribute myAttribute;
MyClass(MyAttribute myAttribute) {
this.myAttribute = myAttribute;
}
MyAttribute getMyAttribute() {
return myAttribute;
}
}
class MySubClass extends MyClass {
MySubClass(MySubAttribute mySubAttribute) {
super(mySubAttribute);
}
}
class MyAttribute {
void doSomething() {
}
}
class MySubAttribute extends MyAttribute {
@Override
void doSomething() {
super.doSomething();
}
void doSomethingElse() {
}
}
Now imagine that I have the following code:
mySubClass.getMyAttribute();
How to make the returned value of type MySubAttribute?