title: Collections.sort no compile time error
body: <p>What is the difference between <code>Collections.sort(list)</code> and <code>Collections.sort(list,null)</code>
  I supposed both of them compared elements in the list in their natural order.</p>
  
  <p>So I tried these two codes:</p>
  
  <p><strong>CODE 1:</strong></p>
  
  <pre><code>List&lt;Object&gt; list=Arrays.asList("hello",123);
  Collections.sort(list);
  </code></pre>
  
  <p><strong>CODE 2:</strong></p>
  
  <pre><code>List&lt;Object&gt; list=Arrays.asList("hello",123);
  Collections.sort(list,null);
  </code></pre>
  
  <p>The latter compiles but former doesn't giving the expected compiler error that instances of class Object are not comparable.
  Why latter does not give compile time error.</p>
  
  <p><strong>EDIT:</strong> Based on the comment given below. I understand why latter doesn't give compile time error but on running it throws <code>ClassCastException : String cannot be converted into Integer</code> . How it deduced that runtime objects are String and Integer because what I think</p>
  
  <pre><code>public static sort(List&lt;Object&gt; list)  ---&gt; Since list was of type object
  {
  // For instances of object in list call the compareTo method 
  }
  </code></pre>
  
  <p>}</p>