What is the correct cast to Collections.sort()?
<p>I have a list of objects that I wish to sort but only if the list's generic type conforms to <code>java.util.Comparable</code>. I'm not sure what the correct cast is though:</p>

<pre><code>private &lt;T extends Widget&gt; void doAction(Class&lt;T&gt; clazz, List&lt;T&gt; list) {
    if (Comparable.class.isAssignableFrom(clazz)) {
        Collections.sort(list);
    }
    // Do more.
}
</code></pre>

<p><code>Collections.sort</code> requires the type parameter to implement <code>java.util.Comparable</code>, So I tried the following which all do not work:</p>

<pre><code>Collections.sort((List&lt;? extends Comparable&lt;T&gt;&gt;)list);
Collections.sort((List&lt;? extends Comparable&gt;)list);
Collections.sort((List&lt;? extends Comparable&lt;? super T&gt;&gt;)list);
Collections.sort((List&lt;T extends Comparable&lt;? super T&gt;&gt;)list);
</code></pre>

<p>And anything else, I was really just guessing. I thought the first would have worked.</p>

<p>Any assistance is appreciated.</p>

<p><strong>UPDATE</strong>: To show how this does not work the following error is raised from the compiler:</p>

<pre><code>com/mycompany/test/WidgetTest.java:[112,20] no suitable method found for sort(java.util.List&lt;T&gt;)
    method java.util.Collections.&lt;T&gt;sort(java.util.List&lt;T&gt;,java.util.Comparator&lt;? super T&gt;) is not applicable
      (cannot instantiate from arguments because actual and formal argument lists differ in length)
    method java.util.Collections.&lt;T&gt;sort(java.util.List&lt;T&gt;) is not applicable
      (inferred type does not conform to declared bound(s)
        inferred: T
        bound(s): java.lang.Comparable&lt;? super T&gt;)
</code></pre>

<p>Note, that <code>Widget</code> does not conform to <code>Comparable</code>, that's intended, but a subclass of <code>Widget</code> may conform which is what I'm trying to test for.</p>
