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

XMLWordPrintable

    • Type: Bug
    • Resolution: Duplicate
    • Priority: P3
    • None
    • Affects Version/s: 6
    • Component/s: 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.

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

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: