title: Java generics, list of lists
body: <p>This thing has me stumped. I have a class as follows:</p>
  
  <pre><code>public class SpecialList implements List&lt;MyType&gt; {
      // overriden methods
  }
  </code></pre>
  
  <p>Now I have the following method contract to respect in a higher class:</p>
  
  <pre><code>public class MyClass {
      private List&lt;SpecialList&gt; bigList = new ArrayList&lt;SpecialList&gt;();
  
      public void doStuff(List&lt;MyType&gt; list)
      {
          bigList.add((SpecialList)list); // does not compile - invalid cast
      }
  }
  </code></pre>
  
  <p>I really am not sure what I am doing wrong here. I have a class that implements the <code>List&lt;MyType&gt;</code> interface, yet I can't cast that class to a <code>List&lt;MyType&gt;</code>? That doesn't make any sense to me.</p>
  
  <p>I am lost. What am I supposed to do to make this work? I suppose this has something to do with generics covariance but at this point I don't know what is wrong here. Can someone point in the right direction? Thanks.</p>