if I override the equals method in the model class and return always false. and the hashCode always returns a constant value. if I create a Object and add it to Set how HashSet/HashMAp detects duplicates?
public class Employee {
int id;
String name;
@Override
equals(){
return false;
}
}
public static void main(String[] args) {
HashMap<Employee,String> hk= new HashMap<Employee,String>();
Employee e1 = new Employee();
e1.setId(18);
e1.setName("roohi");
hk.put(e1, "hello");
hk.put(e1, "hello");
}
if the Equals method returns false i.e e1.equals(e1) returns false. so the values should be added twice but its only added one. Can anyone please explain this. I googled and cleared my concept on HashCode and equals contract but here I am failing.