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

use "Long.valueOf(x)" instead of "new Long(x)"

    XMLWordPrintable

    Details

    • Type: Enhancement
    • Status: Resolved
    • Priority: P4
    • Resolution: Fixed
    • Affects Version/s: 5.0
    • Fix Version/s: 6
    • Component/s: core-libs
    • Labels:
      None

      Description

      In src/share/classes/java/io/ObjectStreamClass.java there are currently several places in which new instances of java.lang.Long are constructed:

      ObjectStreamClass.java:187: return new Long(computeDefaultSUID(cl));
      ObjectStreamClass.java:388: suid = new Long(0);
      ObjectStreamClass.java:425: suid = new Long(0);
      ObjectStreamClass.java:472: suid = new Long(0);
      ObjectStreamClass.java:504: suid = new Long(model.getSerialVersionUID());
      ObjectStreamClass.java:586: suid = new Long(in.readLong());
      ObjectStreamClass.java:1571: return new Long(f.getLong(null));

      Rather than unconditionally creating new Long instances, this code should instead use the method Long.valueOf(long) (introduced in 5.0), which will share instances in some cases, like for values of zero and other low numbers, potentially reducing memory footprint slightly.

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              aozerov Andrey Ozerov
              Reporter:
              peterjones Peter Jones
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: