For details, see the following issue.
https://bugs.openjdk.java.net/browse/JDK-8176335
By the way, if you look at the Character source code ...
public static Character valueOf(char c) {
if (c <= 127) { // must cache
return CharacterCache.cache[(int)c];
}
return new Character(c);
}
In this way, the valueOf
method has a cache mechanism, and the instance creation cost is low.
Recommended Posts