title: How to override generic list return type in java
body: <p>I am trying to override the method which return type as list in sub class like as below example, due to generics issue i can not able to do it in my sub class. I can not able to change my super class code, so how i can resolve the issue? any one can please guide me...many thanks in advance.</p>
  
  <p><strong>Super classes which can not be update:</strong></p>
  
  <pre><code>public class Animal {
             private String legs;
      }
  
  public class TestSuper {
  
      public List&lt;Animal&gt; addAnimals() {
          return animals;
      }
  }
  </code></pre>
  
  <p><strong>Sub classes:</strong></p>
  
  <pre><code>public class Dog extends Animal {
           private String sound;
      }
  
  public class TestSub extends TestSuper {
  
      public List&lt;Dog&gt; addAnimals() { --&gt; I need to override this method but want return type as List of dogs
          return null;
      }
  }
  </code></pre>