I have an interface Damageable as follows
public interface Damageable {
public void handleCollision(float impulse);
}
a class which implements this interface, BaseObject
public class BaseObject implements Damageable
Now in a third class, I have an ArrayList of the type BaseObject
public class ObjectManager {
public ArrayList<BaseObject> bodies;
What I am trying to do is to pass the ArrayList bodies to a method of another class which accepts ArrayList
public CollisionManager( ArrayList<Damageable> _bodies) {
bodies = _bodies;
}
Java does not let me do new CollisionManager(bodies) where bodies is of type ArrayList and BaseObject implements Damageable
I have tried casting. Says cannot cast from
ArrayList<BaseObject> to ArrayList
Also tried using Class<? extends Damageable> but then I'm unable to call methods declared in the interface Damageable. How can I pass the ArrayList?