JDK-4993091 : Performance improvements questionable with new static valueOf() methods
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.lang
  • Affected Version: 5.0
  • Priority: P4
  • Status: Closed
  • Resolution: Duplicate
  • OS: windows_xp
  • CPU: x86
  • Submitted: 2004-02-11
  • Updated: 2004-02-11
  • Resolved: 2004-02-11
Related Reports
Duplicate :  
Description

Name: gm110360			Date: 02/11/2004


FULL PRODUCT VERSION :
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0-beta-b32c)
Java HotSpot(TM) Client VM (build 1.5.0-beta-b32c, mixed mode)

ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows XP [Version 5.1.2600]

A DESCRIPTION OF THE PROBLEM :
Documentation of new 1.5 static methods valueOf() in the java.lang primitive wrapper classes (Integer, Long, etc.) is misleading.  For example, the Integer class valueOf() method reads as follows:

Returns a Integer instance representing the specified int value.  If a new Integer instance is not required, this method should generally be used in preference to the constructor Integer(int), as this method is likely to to yield significantly better space and time performance by cacheing frequently requested values.

Besides the fact that "Returns a Integer" should read "Returns an Integer", "to to" should simply read "to" and "cacheing" should read "caching", here is the source code for the method:

public static Integer valueOf(int i) {
    return new Integer(i);
}

Maybe I am missing something but how is it invoking a method which is wrappering a constructor faster than simply calling the constructor directly?


REPRODUCIBILITY :
This bug can be reproduced always.
(Incident Review ID: 237738) 
======================================================================

Comments
EVALUATION Implementation problems will be addressed by fix to 4990346. ###@###.### 2004-02-11
11-02-2004