I have method with super class as argument in main class.
public class MainClass() {
...
public void myMethod(MyClass class)
...
In runtime this object can be any of its subclasses and it should call different method depending on subclasses in same main class
public class MainClass() {
...
public void mySubMethod(MySubClass1 class)
public void mySubMethod(MuySubClass2 class)
...
Of course, I can use instanceOf or Static Factory Pattern with Enum but still it will be (pseudo code)
public void myMethod(MyClass class) {
if (instanceOf == MySubclass1) mySubMethod((MySubClass1)subClass1Object)
if (instanceOf == MySubclass2) mySubMethod((MySubClass2)subClass2Object)
}
In runtime jvm knows which subclass exactly object is and knows for each sub-method argument should be. I don't have control over MyClass, MySubclass1 and MySubclass2,...
But is there any elegant way to achive this?