title: Compare two objects with "<" or ">" operators in Java
body: <p>How to make two objects in Java comparable using "&lt;" or ">"
  e.g. </p>
  
  <pre><code>MyObject&lt;String&gt; obj1= new MyObject&lt;String&gt;(“blablabla”, 25);
  MyObject&lt;String&gt; obj2= new MyObject&lt;String&gt;(“nannaanana”, 17);
  if (obj1 &gt; obj2) 
      do something. 
  </code></pre>
  
  <p>I've made MyObject class header as</p>
  
  <p><code>public class MyObject&lt;T extends Comparable&lt;T&gt;&gt; implements Comparable&lt;MyObject&lt;T&gt;&gt;</code>
  and created method Comp but all the gain I got is now I can use "sort" on the list of objects, but how can I compare two objects to each other directly? Is </p>
  
  <pre><code>if(obj1.compareTo(obj2) &gt; 0)
       do something
  </code></pre>
  
  <p>the only way?</p>