2 ms·
They accept Object not because they're not type safe. They accept Object because key `equals` method might return `true` for unrelated classes by design, and co
by vbezhenar 9d ago
They accept Object not because they're not type safe. They accept Object because key `equals` method might return `true` for unrelated classes by design, and collections interfaces have to accommodate for that. In other words, you might put key of class C1 into the map, and later use `get` with key of class C2. And if these classes happen to implement `equals` accepting each other, the collections are supposed to work.
So the core issue is that `Object.equals` method isn't type safe. Collections API just follow that.