title: Better alternative for comparing two generics in my class.
body: <p>I need help guys.
  Is there any better version for comparing two generics in this class "TreeBag"?</p>
  
  <p>My current solution is doing this:</p>
  
  <pre><code>public class TreeBag&lt;T&gt; implements Bag&lt;T&gt;, Comparator&lt;T&gt; {
  .
  .
  .
      @Override 
      public int compare(T o1, T o2) {
          int temp = Integer.parseInt(o1.toString()) - Integer.parseInt(o2.toString());
          if (temp &lt; 0)
              return -1;
          else if (temp &gt; 0)
              return 1;
          else
              return 0;
      }
  </code></pre>
  
  <p>That`s my current solution. But I do thing that's a very unsightly solution. 
  Is there any better solution for this problem?</p>
  
  <p>Thanks</p>