Question 16
Back to Exercise
A mutable object is used as a HashMap key and a field used in its hashCode is changed afterwards. What happens?
- A The map updates automatically
- B The entry usually cannot be found any more, because it sits in the bucket for the old hash Correct
- C An exception is thrown
- D The key is removed
Correct Answer: Option B
Prefer immutable keys.
Discussion & Comments 0
Share your method, a shortcut, or ask about a step you didn't follow.
No comments yet. Be the first to share your solution!