I’m not sure if this is what it’s called, but here is the problem:
I have a superclass with three subclasses.
Let’s say Superclass, Subclass1, Subclass2,Subclass3
I have another class with the following overloaded method:
public void exampleMethod (Subclass1 object1){
//Method to be called if the object is of subclass 1
}
public void exampleMethod (Subclass2 object2){
//Method to be called if the object is of subclass 2
}
public void exampleMethod (Subclass3 object3){
//Method to be called if the object is of subclass 3
}
Is there a way for me to call the overloaded method from the superclass while dynamically casting the method parameter to the object type at runtime?
anotherClass.exampleMethod(this);
Is that what you mean?
Probably better to do
You can then call
callExampleMethodin the superclass, and it will delegate properly.