title: How to pass a method a List<Interface> instead of List<Class>?
body: <p>I have some objects that implement a common interface. Let's say I have <code>Apple</code> and some other <code>Fruits</code> that implement <code>HasSeed</code> and return their number of seeds.</p>
  
  <p>I then have a service method, call it <code>FruitProcessor</code> here, with an <code>addAll(List&lt;HasSeed&gt;)</code> class. I thought I then can pass in a list of objects that implement the <code>HasSeed</code> interface, like a list of apples.</p>
  
  <p>But I can't and the compiler complains that it's not applicable for the arguments.
  One more thing: I cannot change the <code>List&lt;Apple&gt;</code> to a <code>List&lt;HasSeed&gt;</code>. BUT I need a method in my FruitProcessor that can take any list of objects, and then calls <code>getSeeds()</code> no matter what object it is.</p>
  
  <p>How could I adapt the following?</p>
  
  <pre><code>class Fruit {};
  class Apple extends Fruit implements HasSeed {
     @Override
     int getSeeds() {
         return 5; //just an example
     }
  }
  
  class FruitProcessor {
      static void addAll(List&lt;HasSeed&gt; list) {
          for (HasSeed seed : list) {
              Sysout("the fruit added contained seeds: " + list.getSeeds());
          }
      }
  }
  
  class FruitStore {
      List&lt;Apple&gt; apples;
      FruitProcessor.addAll(apples); //The method addAll(List&lt;HasSeed&gt;) in the type FruitProcessor is not applicable for the arguments (List&lt;Apple&gt;)
  }
  </code></pre>