Re: HashMap get/put
Peter Duniho wrote:
....
But your example simply reinforces my point. In a framework with
reified generics, looking for a dictionary entry using an object of the
wrong type wouldn't make sense at all. The alternative that I describe
makes sense in such a framework, but perhaps not in Java (though
frankly, they didn't _have_ to implement equals() that way and I object
to the fact that they did). In such a framework, having compile time
support to avoid needless operations is possible and useful. In Java,
not so much.
....
I think the equals design was a consequence of some deeply embedded
decisions, especially the idea that all instance methods are virtual (in
C++ terminology - the distinction I am making does not exist in Java).
There is a good case for the way List defines equals. It prevents a
change in the choice of implementing class from affecting List equality.
If Java had non-virtual methods and multiple inheritance, List could be
an abstract class with its own equals method that would be used when the
target expression is of type List.
Given the all-virtual decision, the only way to get that behavior for
List expressions is to push it down to the equals method member in each
implementing class. That leads to the ArrayList that considers itself
equal to a Stack.
Patricia