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