title: Type mismatch for Class Generics
body: <p>I have the following code that won't compile and although there is a way to make it compile I want to understand why it isn't compiling. Can someone enlighten me as to specifically why I get the error message I will post at the end please?</p>
  
  <pre><code>public class Test {
      public static void main(String args[]) {
          Test t = new Test();
          t.testT(null);
      }
  
      public &lt;T extends Test&gt; void testT(Class&lt;T&gt; type) {
          Class&lt;T&gt; testType = type == null ? Test.class : type; //Error here
          System.out.println(testType);
      }
  }
  </code></pre>
  
  <p><code>Type mismatch: cannot convert from Class&lt;capture#1-of ? extends Test&gt; to Class&lt;T&gt;</code></p>
  
  <p>By casting <code>Test.class</code> to <code>Class&lt;T&gt;</code> this compiles with an <code>Unchecked cast</code> warning and runs perfectly.</p>