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));
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));
- duplicates
-
JDK-6480728 Byte.valueOf(byte) returns a cached value but Byte.valueOf(String)
- Resolved