<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>

Remove the conditional and the error is a little nicer...
```
```
public class Test {
    public static void main(String args[]) {
        Test t = new Test();
        t.testT(null);
    }

    public <T extends Test> void testT(Class<T> type) {
    Class<T> testClass = Test.class;
        System.out.println(testClass);
    }
}

Test.java:10: incompatible types
found   : java.lang.Class<Test>
required: java.lang.Class<T>
        Class<T> testClass = Test.class;
```
```