title: Generic method with parameters vs. non-generic method with wildcards
body: <p>According to <a href="http://www.angelikalanger.com/GenericsFAQ/FAQSections/ProgrammingIdioms.html#FAQ302B" rel="noreferrer">this entry in the Java Generics FAQ</a>, there are some circumstances where a generic method has no equivalent non-generic method that uses wildcard types.  According to that answer,</p>
  
  <blockquote>
    <p>If a method signature uses multi-level wildcard types then there is always a difference between the generic method signature and the wildcard version of it.</p>
  </blockquote>
  
  <p>They give the example of a method <code>&lt;T&gt; void print1( List &lt;Box&lt;T&gt;&gt; list)</code>, which "requires a list of boxes of the same type."  The wildcard version, <code>void print2( List &lt;Box&lt;?&gt;&gt; list)</code>, "accepts a heterogenous list of boxes of different types," and thus is not equivalent.</p>
  
  <p>How do you interpret the the differences between the following two method signatures:</p>
  
  <pre class="lang-java prettyprint-override"><code> &lt;T extends Iterable&lt;?&gt;&gt; void f(Class&lt;T&gt; x) {}
                           void g(Class&lt;? extends Iterable&lt;?&gt;&gt; x) {}
  </code></pre>
  
  <p>Intuitively, it seems like these definitions should be equivalent.  However, the call <code>f(ArrayList.class)</code> compiles using the first method, but the call <code>g(ArrayList.class)</code> using the second method results in a compile-time error: </p>
  
  <pre class="lang-java prettyprint-override"><code>g(java.lang.Class&lt;? extends java.lang.Iterable&lt;?&gt;&gt;) in Test
      cannot be applied to (java.lang.Class&lt;java.util.ArrayList&gt;)
  </code></pre>
  
  <p>Interestingly, both functions can be called with each others' arguments, because the following compiles:</p>
  
  <pre class="lang-java prettyprint-override"><code>class Test {
      &lt;T extends Iterable&lt;?&gt;&gt; void f(Class&lt;T&gt; x) {
          g(x);
      }
      void g(Class&lt;? extends Iterable&lt;?&gt;&gt; x) {
          f(x);
      }
  }
  </code></pre>
  
  <p>Using <code>javap -verbose Test</code>, I can see that <code>f()</code> has the generic signature </p>
  
  <pre class="lang-java prettyprint-override"><code>&lt;T::Ljava/lang/Iterable&lt;*&gt;;&gt;(Ljava/lang/Class&lt;TT;&gt;;)V;
  </code></pre>
  
  <p>and <code>g()</code> has the generic signature</p>
  
  <pre class="lang-java prettyprint-override"><code>(Ljava/lang/Class&lt;+Ljava/lang/Iterable&lt;*&gt;;&gt;;)V;
  </code></pre>
  
  <p>What explains this behavior?  How should I interpret the differences between these methods' signatures? </p>