Why is java's Map<K,V>
declaring the methods like this
V get(Object key) {....}
or
boolean containsKey(Object key) {....}
I was expecting those to be
V get(K key) {....}
or
boolean containsKey(K key) {....}
instead.
Got bitten by this, defined a Map<String,String>
and happily called myMap.get(myEnum)
, got no compiler error. Yay!
Why bother with specifying K (for type safety, haha) if they prefer the 'flexibility' of Object?
Thanks