title: Java Generic Type flexibility with subtype assignment
body: <p>I have the following structure. A parent class:</p>
  <pre><code>public class MyTree&lt;E extends MyTree&lt;E&gt;&gt;{
     List&lt;E&gt; children;
  
     public MyTree(List&lt;E&gt; ls){
        this.children = ls;
     }
     
     public void insert(E t){
       this.children.add(t);
     }
  }
  </code></pre>
  <p>a child class:</p>
  <pre><code>public class SpecTree&lt;E&gt; extends MyTree&lt;SpecTree&lt;E&gt;&gt;{
     private E value;
  
     public SpecTree(E value){
        super(new ArrayList&lt;&gt;());
        this.value = value;
     }
  }
  </code></pre>
  <p>Now from main, I want to insert a tree into another tree.</p>
  <pre><code>SpecTree&lt;Number&gt; st = new SpecTree&lt;&gt;(0);
  st.insert(new SpecTree&lt;Integer&gt;(2));      //incompatible type error
  </code></pre>
  <p>The <code>SpecTree</code> must be able to accept new children with values that are subtype of the current tree. For example, I should be able to insert a  <code>SpecTree&lt;Integer&gt;</code> into <code>SpecTree&lt;Number&gt;</code>.</p>
  <p>Is it possible to do without changing the structure of code and changing only the type parameters?</p>