title: Java self type recursive type parameters and inheritance error in javac
body: <p>Why does this code not compile?</p>
  
  <pre><code>public class x
  {
      private void test()
      {
          handle(new ThingA());
          handle(new ModifiedThingA());
      }
  
      private &lt;T extends BaseThing&lt;T&gt;, X extends T&gt; java.util.List&lt;T&gt; handle(X object)
      {
          return object.getList();
      }
  
      private static class BaseThing&lt;T extends BaseThing&lt;T&gt;&gt;
      {
          public java.util.List&lt;T&gt; getList()
          {
              return null;
          }
      }
  
      private static class ThingA
          extends BaseThing&lt;ThingA&gt;
      {
      }
  
      private static class ModifiedThingA
          extends ThingA
      {
      }
  }
  </code></pre>
  
  <p>Java 6 gives this this error in <code>handle(new ModifiedThingA());</code>:</p>
  
  <pre><code>x.java:6: &lt;T,X&gt;handle(X) in x cannot be applied to (x.ModifiedThingA)
              handle(new ModifiedThingA());
              ^
  </code></pre>
  
  <p>Java 7 does not even like <code>handle(new ThingA());</code>, this is the Java 7 output:</p>
  
  <pre><code>x.java:5: error: invalid inferred types for T; inferred type does not conform to declared bound(s)
              handle(new ThingA());
                    ^
      inferred: ThingA
      bound(s): CAP#1
    where T,X are type-variables:
      T extends BaseThing&lt;T&gt; declared in method &lt;T,X&gt;handle(X)
      X extends T declared in method &lt;T,X&gt;handle(X)
    where CAP#1 is a fresh type-variable:
      CAP#1 extends BaseThing&lt;CAP#1&gt; from capture of ?
  x.java:6: error: invalid inferred types for T; inferred type does not conform to declared bound(s)
              handle(new ModifiedThingA());
                    ^
      inferred: ModifiedThingA
      bound(s): CAP#1
    where T,X are type-variables:
      T extends BaseThing&lt;T&gt; declared in method &lt;T,X&gt;handle(X)
      X extends T declared in method &lt;T,X&gt;handle(X)
    where CAP#1 is a fresh type-variable:
      CAP#1 extends BaseThing&lt;CAP#1&gt; from capture of ?
  2 errors
  </code></pre>
  
  <p>It seems to me that <code>javac</code> is mistaking <code>ModifiedThingA</code> for a <code>BaseThing&lt;ModifiedThingA&gt;</code> when it is in fact a <code>BaseThing&lt;ThingA&gt;</code>. Is this my bug or <code>javac</code>'s?</p>