IMC Trading Interview Question: In the Java specification, it... | Glassdoor

Interview Question

Java Software Developer Interview

In the Java specification, it is considered good practice

  to override .equals() and .hashCode() both together. In the context of HashMap, explain why implementing only one of the two instead of both can cause problems. You must consider both cases.
Answer

Interview Answer

1 Answer

0

If two objects are equal according to the equals(Object) method, then calling the hashCode method on each of the two objects must produce the same integer result.

Anonymous on Oct 25, 2015

Add Answers or Comments

To comment on this, Sign In or Sign Up.