There was such a code.
Custom HashMap class that inherits HashMap
@Override
public Object put(Object key, Object value) {
//Make the key lowercase
return super.put(key.toString().toLowerCase(), value);
}
Code using a custom HashMap
CustomHashMap map = new CustomHashMap();
map.putAll(valueMap); //Keys are all lowercase in Java 7
When I upgraded from Java7 to Java8, the map key did not become lowercase and it no longer behaved as before.
When I read the code of HashMap,
--In Java7, put () is called from putAll () --In Java8, put () is not called ** from putAll () **
It turned out that was the cause. That is, the overridden put method is not called. Should I think that putAll happened to work in Java 7 because it wasn't overridden? (Maybe I was reading the Java 7 implementation.)
Recommended Posts