title: Java Generics - Comparable interface
body: <p>In the code below <code>Comparable</code> interface is used to ensure x and y should be of same reference type but as V is extending T so V should be of the same type as T or subclass of T then what is the point of using <code>Comparable</code> interface.
  Also if I am not using <code>Comparable</code> interface then the last call to <code>isIf</code> method is getting compile despite x and y are of different types.
  Can anyone explain the use <code>Comparable</code> interface regarding this program?</p>
  
  <pre><code>public class Generics_13 {
  
      static &lt;T extends Comparable&lt;T&gt;, V extends T&gt; boolean isIn(T x, V[] y) {
          for(int i = 0;i &lt; y.length;i++) 
              if(x.equals(y[i])) return true;
  
          return false;
      }
  
      public static void main(String[] args) {
          Integer nums[] = {10, 20, 30};
  
          if(isIn(10, nums))
              System.out.println("10 belongs to the array");
          if(!isIn(60, nums))
              System.out.println("70 doesnt belong to the array");
  
          String arr[] = {"Neeraj", "Parth", "Ritum"};
          if(!isIn("abc", arr))
              System.out.println("abc doesnt belongs to the array");
  
          /*if(isIn("String", nums))      //  illegal
              System.out.println("This wont compile");
          */
      }
  }
  </code></pre>