The latest impl of Integer.valueOf(String) does not take advantage of the caching capabilities introduced in JDK 1.5.
The impl currently looks as follows:
public static Integer valueOf(String s) throws NumberFormatException
{
return new Integer(parseInt(s, 10));
}
meaning each invocation will create a new Integer instance.
Why couldn't the impl take advantage of the cache lookup implemented by Integer.valueOf(int), as follows:
public static Integer valueOf(String s) throws NumberFormatException
{
return valueOf((parseInt(s, 10)));
}
Same is true for java.lang.Long.
The impl currently looks as follows:
public static Integer valueOf(String s) throws NumberFormatException
{
return new Integer(parseInt(s, 10));
}
meaning each invocation will create a new Integer instance.
Why couldn't the impl take advantage of the cache lookup implemented by Integer.valueOf(int), as follows:
public static Integer valueOf(String s) throws NumberFormatException
{
return valueOf((parseInt(s, 10)));
}
Same is true for java.lang.Long.
- duplicates
-
JDK-5005319 wrapper objects created in wrapper classes are not cached
- Closed