HashMap # putAll () behaves differently between Java 7 and Java 8

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

HashMap # putAll () behaves differently between Java 7 and Java 8
[Java] Difference between Hashmap and HashTable
[Java] Difference between == and equals
Differences between "beginner" Java and Kotlin
[Java] Relationship between H2DB and JDBC
[Java] Difference between array and ArrayList
Differences between Java and .NET Framework
[Java] Difference between Closeable and AutoCloseable
[Java] Difference between StringBuffer and StringBuilder
[Java] Difference between length, length () and size ()
Conversion between Kotlin nullable and Java Optional
Relationship between kotlin and java access modifiers
[For beginners] Difference between Java and Kotlin
[Java] Differences between instance variables and class variables
[Note] Cooperation between Java and DB (basic)
[Java] Difference between Intstream range and rangeClosed
Difference between int and Integer in Java
[Java] Understand the difference between List and Set
Java HashMap class
Difference between next () and nextLine () in Java Scanner
Summarize the differences between C # and Java writing
Java and JavaScript
Distinguish between positive and negative numbers in Java
[Java] Difference between "final variable" and "immutable object"
[Java] Difference between static final and final in member variables
[JAVA] What is the difference between interface and abstract? ?? ??
Mutual conversion between Java objects and JSON using Moshi
What is the difference between Java EE and Jakarta EE?
[Java beginner] Difference between length and length () ~ I don't know ~
Getters and setters (Java)
[Java] Thread and Runnable
Java true and false
[Java] String comparison and && and ||
Read Java HashMap source
Java --Serialization and Deserialization
[Java] Arguments and parameters
Switch between JDK 7 and JDK 8
timedatectl and Java TimeZone
[Java] Branch and repeat
Difference between vh and%
[Java] Variables and types
Difference between i ++ and ++ i
java (classes and instances)
Initializing HashMap in Java
[Java] Overload and override
[Java Bronze learning] Differences between encapsulation, data hiding, and information hiding
Difference between Java and JavaScript (how to find the average)
What has changed between Effective Java 2nd Edition and 3rd Edition
[Java] Difference between assignment of basic type variable and assignment of reference type variable
[Java] Check the difference between orElse and orElseGet with IntStream
Think about the differences between functions and methods (in Java)
Differences in how to handle strings between Java and Perl