Pergunta de entrevista da empresa IMC Trading

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.

Resposta da entrevista

Sigiloso

26 de out. de 2015

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.