title: Ordering by date. Comparator. Java
body: <p>the next snippet taken from <a href="http://docs.oracle.com/javase/tutorial/collections/interfaces/order.html" rel="nofollow">this</a> java tutorial, compares the second argument object to the first one rather than viceversa.
  *The method hireDate() returns a Date object signifying the hiring date of that particular employee. </p>
  
  <pre><code>import java.util.*;
  public class EmpSort {
      static final Comparator&lt;Employee&gt; SENIORITY_ORDER = 
                                          new Comparator&lt;Employee&gt;() {
              public int compare(Employee e1, Employee e2) {
                  return e2.hireDate().compareTo(e1.hireDate());
              }
      };
  </code></pre>
  
  <p>Here is the java tutorial explanation:</p>
  
  <blockquote>
    <p>Note that the Comparator passes the hire date of its second argument
    to its first rather than vice versa. The reason is that the employee
    who was hired most recently is the least senior; sorting in the order
    of hire date would put the list in reverse seniority order.</p>
  </blockquote>
  
  <p>Still I do not get why by inverting e1 and e2 in <code>compareTo</code> it should solve the issue.</p>
  
  <p>Any further clarification?</p>
  
  <p>Thanks in advance.</p>