title: Overriding hashcode and equals method in java?
body: <p>I have the classes below:</p>
  
  <pre><code>public class Sample implements java.io.Serializable{
  
    //POJO with two fields and getters/setters
  
     private String name;
     private Integer id;
  
     //This POJO does not override equals() and hashCode()
  }
  
  public class B{
   private Sample sample;
  
    //here i need override hashcode and equals() based on **sample** property.
  
  
  }
  </code></pre>
  
  <p>When i tried overriding equals() and hashCode() in the <strong>B</strong> class I got the error below in Eclipse.</p>
  
  <blockquote>
    <p>The field type com.mypackage.Sample does not implement hashCode()  and equals() - The resulting code may not work correctly.</p>
  </blockquote>
  
  <p>Now how can I compare two <strong>B</strong> instances whether equals or not based on the Sample property?
  I cannot modify Sample class.</p>