title: Java Generics not working
body: <p>Why Generics not working in my machine. Why below code not working in Eclipse without Type casting to the <code>String</code>. I am using Java 1.6</p>
  
  <pre><code>package com.withgeneric;
  
   class Util {
      // Generic static method
      public static &lt;K, V&gt; boolean compare(Pair&lt;K, V&gt; p1, Pair&lt;K, V&gt; p2) {
          return p1.getKey().equals(p2.getKey()) &amp;&amp;
                 p1.getValue().equals(p2.getValue());
      }
  }
  
   class SPair&lt;K, V&gt; {
  
          private K key;
          private V value;
  
          // Generic constructor
          public SPair(K key, V value) {
              this.key = key;
              this.value = value;
          }
  
          // Generic methods
          public void setKey(K key) { this.key = key; }
          public void setValue(V value) { this.value = value; }
          public K getKey()   { return key; }
          public V getValue() { return value; }
      }
  
  
  
  public class GenericMethod {
  
      /**
       * @param args
       */
      public static void main(String[] args) {
  
          Pair&lt;Integer, String&gt; p1 = new SPair&lt;&gt;(1, "apple"); //Giving Error
          Pair&lt;Integer, String&gt; p2 = new SPair&lt;&gt;(2, "pear"); //Giving Error
          boolean same = Util.&lt;Integer, String&gt;compare(p1, p2);
  
          // TODO Auto-generated method stub
  
      }
  
  }
  </code></pre>