title: How to compare objects by multiple fields
body: <p>Assume you have some objects which have several fields they can be compared by:</p>
  
  <pre><code>public class Person {
  
      private String firstName;
      private String lastName;
      private String age;
  
      /* Constructors */
  
      /* Methods */
  
  }
  </code></pre>
  
  <p>So in this example, when you ask if:</p>
  
  <pre><code>a.compareTo(b) &gt; 0
  </code></pre>
  
  <p>you might be asking if a's last name comes before b's, or if a is older than b, etc...</p>
  
  <p>What is the cleanest way to enable multiple comparison between these kinds of objects without adding unnecessary clutter or overhead?</p>
  
  <ul>
  <li><code>java.lang.Comparable</code> interface allows comparison by one field only</li>
  <li>Adding numerous compare methods (i.e. <code>compareByFirstName()</code>, <code>compareByAge()</code>, etc...) is cluttered in my opinion.</li>
  </ul>
  
  <p>So what is the best way to go about this?</p>