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. If you create a HashMap<String,String> and then by mistake try to use an int as key when looking up a value, you will not get any compile-time error. Worse yet, you will not even get any run-time error, it will just appear as if there is no value with that key (which in some sense is correct).