title: Java objects are equal though hashcode is different
body: <p>While reading about equals() and hashcode(), I came to know that if two objects are equal, then their hashcodes must be equal, though not vice-versa.</p>
  
  <p>But below example doesn't reflect this.</p>
  
  <pre><code>class Employee{
  
    private String name;
  
    Employee(String name){
      this.name = name;
    }
  
    @Override
    public boolean equals(Object obj) {           
          if (this == obj)
              return true;
          if (obj == null)
              return false;
          if (getClass() != obj.getClass())
              return false;
          Employee other = (Employee) obj;
          if (name == null) {
              if (other.name != null)
                  return false;
          } else if (!name.equals(other.name))
              return false;
          return true;
      }
  
  }
  </code></pre>
  
  <p>Now if I create two Employee objects as</p>
  
  <pre><code>Employee e1 = new Employee("hi");
  Employee e2 = new Employee("hi");
  </code></pre>
  
  <p>If i do, <code>e1.equals(e2)</code>, it returns <strong>true</strong> even though their hashcodes are different which is evident from printing, <code>e1.hashcode()</code> and <code>e2.hashcode()</code>.</p>
  
  <p>Can someone explain me?</p>