title: How to set constraints on generic types in Java?
body: <p>I have a generic class:</p>
  
  <pre><code>public class ListObject&lt;T&gt;
  {
      // fields
      protected T _Value = null;
        // ..
  }
  </code></pre>
  
  <p>Now I want to do something like the following:</p>
  
  <pre><code>ListObject&lt;MyClass&gt; foo = new ListObject&lt;MyClass&gt;();
  ListObject&lt;MyClass&gt; foo2 = new ListObject&lt;MyClass&gt;();
  foo.compareTo(foo2);
  </code></pre>
  
  <p><strong>Question:</strong></p>
  
  <p>How can I define the <code>compareTo()</code> method with resprect to the generic <code>T</code>?</p>
  
  <p>I guess I have to somehow implement a constraint on the generic <code>T</code>, to tell that <code>T</code> implements a specific interface (maybe <code>Comparable</code>, if that one exists).</p>
  
  <p>Can anyone provide me with a small code sample?</p>