JDK-6493563 : Provide a method caches the valueOf(String)
  • Type: Enhancement
  • Component: core-libs
  • Sub-Component: java.lang
  • Affected Version: 6
  • Priority: P5
  • Status: Closed
  • Resolution: Duplicate
  • OS: windows_xp
  • CPU: x86
  • Submitted: 2006-11-14
  • Updated: 2010-04-26
  • Resolved: 2006-11-14
Related Reports
Duplicate :  
Description
A DESCRIPTION OF THE REQUEST :
Currently these methods use a small cache
Byte.valueOf(byte)
Short.valueOf(short)
Integer.valueOf(int)
Long.valueOf(long)

However these methods do not.
Byte.valueOf(String)
Short.valueOf(String)
Integer.valueOf(String)
Long.valueOf(String)

Suggest having a method which takes a String and uses the same object pool as the valueOf(primative)

JUSTIFICATION :
It useful to pool objects converted from a String in the same way it is useful to wrap primative values.

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
valueOf(String) should be pooled for the same values as valueOf(primative)
ACTUAL -
valueOf("0") returns a new object every time.

CUSTOMER SUBMITTED WORKAROUND :
use
Long.valueOf(Long.parseLong(asStr));
Integer.valueOf(Integer.parseInt(asStr));
Short.valueOf(Short.parseShort(asStr));
Byte.valueOf(Byte.parseByte(asStr));