Let's set up an hypothetical scenario. I have parent class
public class A {
protected void doSomething(){
//do something the A way
}
}
And child class
public class B extends A{
@Override
protected void doSomething(){
// do something the B way
}
}
And i have some hypothetical class that:
public class SomeClass implements someInterface{
@Override
public void someMethod(A aObject){
aObject.doSomething();
}
}
But i want to use the behavior of B, i can't change the method parameter nor i can downcast it to B.
Obviously i'm handling a bigger problem but this is the same principle, the answer i have for myself is to clone the properties of A into B, then use B. But before that i'd like to hear more opinions.
EDIT: Constraint, i can't pass an instance of B to the method nor use the instanceof method.
EDIT 2: I never receive an instance of B because someClass overrides this method from an interface that must always use an instance of A.
EDIT 3: This is a situation generated by poorly designed legacy code i ran into, i just wanted to figure out the faster but clean way to fix as an excercise.