title: Java generics - Supertype references
body: <p>If i have understood generics correctly, a method with parameters declared as <code>&lt;? super T&gt;</code> will accept any reference that is either of Type <code>T</code> or a super type of <code>T</code>. I am trying to test this with the following bit of code but the compiler does not like it. </p>
  
  <pre><code>class Animal{}
  class Dog extends Animal{}
  class Cat extends Animal{}
  
  class ZiggyTest2{
  
      public static void main(String[] args){                 
  
          List&lt;Animal&gt; anim2 = new ArrayList&lt;Animal&gt;();
          anim2.add(new Animal());
          anim2.add(new Dog());
          anim2.add(new Cat());   
  
          testMethod(anim2);
      }
  
      public static void testMethod(ArrayList&lt;? super Dog&gt; anim){
          System.out.println("In TestMethod");
          anim.add(new Dog());
          //anim.add(new Animal());
      }
  }
  </code></pre>
  
  <p>Compiler error is :</p>
  
  <pre><code>ZiggyTest2.java:16: testMethod(java.util.ArrayList&lt;? super Dog&gt;) in ZiggyTest2 cannot be applied to (java.util.List&lt;Animal&gt;)
                  testMethod(anim2);
                  ^
  1 error
  </code></pre>
  
  <p>I dont understand why i cant pass in anim2 since it is of type <code>&lt;Animal&gt;</code> and Animal is a super type of Dog. </p>
  
  <p>Thanks</p>