I have some arraylist with different objects of the same interface type, e.g:
Interface interface {}
class A implements interface {}
class B implements interface {}
I also have an overloaded method that implements all those inherited objects of the interface:
public void doSomething(A obj) {}
public void doSomething(B obj) {}
The compiler also forces me to write an overloaded method with the interface:
public void doSomething(interface obj) {}
Then I go through the values of the list and call the method:
for (interface obj: myList) {
doSomething(obj);
}
Now since the type of obj is 'interface', the doSomething(interface obj) is called instead of say doSomething(B obj) in case obj were actually of the type B.
Can I make java do otherwise, so it calls doSomething(A obj) when obj is of the type A and doSomething(B obj) when obj is of the type B?