How come I get compile time error when use Collections.sort() but not with TreeSet.add(new Object())
<p>How come I'm allowed to do this:</p>

<pre><code>TreeSet&lt;Object&gt; treeSet = new TreeSet&lt;Object&gt;();
treeSet.add(new Object());
</code></pre>

<p>But not this:</p>

<pre><code>final List&lt;Object&gt; objects = new ArrayList&lt;Object&gt;();
Collections.sort(objects);
</code></pre>

<p>The first one gives me an ClassCastException but the second one gives me a compile error. As I understand it the actual problem is the same in both cases: <code>java.lang.Object</code> does not implement the <strong>Comparable</strong> interface.</p>

<p>UPDATE:
Hmm for some reason this only applies for Java 7 and not 6. 
Am I being stupid or tired? Could someone please shed some light on this?</p>

<p>UPDATE #2:
I do get different results depending on java versions. Please see picture:
<img src="http://i.stack.imgur.com/VWux4.png" alt="enter image description here"></p>
