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

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

XMLWordPrintable

    • Icon: Enhancement Enhancement
    • Resolution: Fixed
    • Icon: P4 P4
    • 6
    • 5.0
    • core-libs
    • None

      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.

            aozerov Andrey Ozerov
            peterjones Peter Jones (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: