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

Byte.valueOf(byte) returns a cached value but Byte.valueOf(String)

XMLWordPrintable

    • Icon: Enhancement Enhancement
    • Resolution: Fixed
    • Icon: P5 P5
    • 7
    • 5.0, 6
    • core-libs
    • b74
    • generic, x86, sparc
    • generic, solaris_8, solaris_10, windows_xp

      A DESCRIPTION OF THE REQUEST :
      Byte.valueOf(byte) notes
           * If a new <tt>Byte</tt> instance is not required, this method
           * should generally be used in preference to the constructor
           * {@link #Byte(byte)}, as this method is likely to yield
           * significantly better space and time performance by caching
           * frequently requested values.

      Please provide a version of valueOf which takes a String and does the same thing. This also holds for Short, Integer and Long.

      JUSTIFICATION :
      If it is a good idea for converting byte to Byte it should also be a good idea from converting String to Byte.
      I understand there may be backward compatibility issues but there should be an elegant way to resolve this.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      valueOf(String) behaves in the same way as valueOf(byte)
      ACTUAL -
      valueOf(String) does the same as new Byte(String)
      valueOf(byte) notes that using the cache has many benifits.

      ---------- BEGIN SOURCE ----------
      public static Byte valueOf(String s, int radix) throws NumberFormatException {
      return valueOf(parseByte(s, radix));
          }
      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      Call Byte.valueOf(Byte.parseByte(String))
      This is tricky to do with reflections in an elegant way!

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

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: