Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-6493563

Provide a method caches the valueOf(String)

XMLWordPrintable

    • Icon: Enhancement Enhancement
    • Resolution: Duplicate
    • Icon: P5 P5
    • None
    • 6
    • core-libs
    • x86
    • windows_xp

      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));

            Unassigned Unassigned
            tyao Ting-Yun Ingrid Yao (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: