Possible Duplicate:
What are the reasons why Map.get(Object key) is not (fully) generic
I have a question about the Generic java collections, specifically Map. I notice that the get, contains and similar methods that require a parameter (usually the key) take an Object as the parameter, while I would have expected them to take something of class K, e.g. rather than get(Object key) I would expect get(K key). Can anyone explain the reason for this?
As it says here, it is because the object you pass to get does not have to be equal to the type of the key you are trying to retrieve.
The only condition is that their
equalsmethod returntrue.EDIT: As Peter Lawrey pointed out, the
hashcodeshould be the same.