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

Impl of Integer.valueOf(String) is inefficient, does not leverage JDK 1.5 caching capabilities

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P3 P3
    • None
    • 6
    • core-libs
    • None
    • generic
    • generic

      The latest impl of Integer.valueOf(String) does not take advantage of the caching capabilities introduced in JDK 1.5.

      The impl currently looks as follows:

          public static Integer valueOf(String s) throws NumberFormatException
          {
              return new Integer(parseInt(s, 10));
          }

      meaning each invocation will create a new Integer instance.

      Why couldn't the impl take advantage of the cache lookup implemented by Integer.valueOf(int), as follows:

          public static Integer valueOf(String s) throws NumberFormatException
          {
              return valueOf((parseInt(s, 10)));
          }

      Same is true for java.lang.Long.

            darcy Joe Darcy
            jlueheorcl Jan Luehe (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: