13 August 2009
java.util.Map is broken in Java 5
Java 5 added generics. The collection classes was modified to make use generics to provide compile-time type-safe collections. Sadly, this was not done properly.
The worst problem is in the interface java.util.Map:
public interface Map<K,V> { // more methods... V get(Object key); V remove(Object key); boolean containsKey(Object key); boolean containsValue(Object key); } The key parameters to these methods ought to be declared to be K and not Object. Now we don’t get any type-safety for those methods.