title: Complex Generics Combinations
body: <p>Imagine a generic class MySet which maintains a parent MySet instance and a child MySet instance. The idea is that the parent should be able to hold a superset of T and the child a subset. So given the following sample, consider the following problem:</p>
  
  <pre><code>class MySet&lt;T&gt; {
  
    MySet&lt;? extends T&gt; child; 
  
    void doStuff (Collection&lt;? extends T&gt; args) {
      child.doStuff(this, args);
    }
  
  }
  </code></pre>
  
  <p>EDIT: fixed question and sample code to reflect the real problem</p>
  
  <p>Now, the child generic <code>&lt;T</code>> may be more restrictive than the parent's <code>&lt;T</code>>, so the parent must pass in a Collection<code>&lt;X</code>> where <code>&lt;X</code>> conforms to the child's <code>&lt;T</code>>. Keep in mind that this parent->child chain could extend to be arbitrarily long. Is there any way to arrange the generics so that parent.doStuff(...) will compile, ie, so that it can only be called with the arguments of it's most restrictive child?</p>
  
  <p>This would mean that the java compiler would pass up generic information all the way up the parent->child chain to determine what the allowable arguments to doStuff could be, and I don't know if it has that capability.</p>
  
  <p>Is the only solution to ensure children cannot be more restrictive than their parents using generics (ie, MySet<code>&lt;T</code>> child; rather than MySet<code>&lt;? extends T</code>>) and have children be more restrictive than their parents elsewhere in the code?</p>