Đang mở hậu trường...
3 câu hỏi kỹ thuật chủ đề Ngôn ngữ & OOP, song ngữ Anh-Việt, có đáp án và giải thích.
A junior developer creates a `User` class and overrides `equals()` to compare users by their `id` field, but forgets to override `hashCode()`. He then puts a `User` object into a `HashMap<User, String>` and later tries to look it up using a *different* `User` instance that has the same `id`. What is the most likely result?
You are architecting a high-throughput caching service using java.util.HashMap, where the system keys are composite objects that must be updated frequently based on external events. If a developer uses a mutable object as a key and modifies its internal fields after the object has been inserted into the HashMap, what is the primary consequence observed during the object's lifecycle in production?
A Java service stores customer records in a HashSet<Customer>. Two Customer objects with the same customerId must be treated as duplicates, but the set currently keeps both objects. What is the most appropriate fix?