JDK-6490545 : Impl of Integer.valueOf(String) is inefficient, does not leverage JDK 1.5 caching capabilities
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.lang
  • Affected Version: 6
  • Priority: P3
  • Status: Closed
  • Resolution: Duplicate
  • OS: generic
  • CPU: generic
  • Submitted: 2006-11-06
  • Updated: 2010-04-02
  • Resolved: 2006-11-09
Related Reports
Duplicate :  
Description
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.

Comments
EVALUATION Subset of 5005319; closing as a duplicate.
09-11-2006