Machine-translated by Google. Questions are authored in English.
Top

Discussion

Which of these statements about whether unequal objects must have different hash codes is correct?

  • A.Unequal objects must return distinct hash codes, or the contract is broken.
  • B.Unequal objects must return distinct hash codes only when stored in the same collection.
  • C.Unequal objects must return hash codes of opposite sign, so collisions cannot occur.
  • D.Unequal objects may share a hash code, though distinct values help hash table performance.

Answer: D

The javadoc says it is not required that unequal objects produce distinct results, while noting that doing so may improve hash table performance. Collisions are therefore legal and expected, which is why a hash table still has to compare candidates with equals.

No comment is present. Be the first to comment.
Loading…

Post your comment

Please log in or register to post a comment.