Uploaded image for project: 'Commons Lang'
  1. Commons Lang
  2. LANG-738

Use internal Java's Number caches instead creating new objects

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 3.0
    • 3.0.1
    • lang.*
    • None

    Description

      Use internal Java's Number caches instead creating new objects:

      • Use more efficient Integer cache: Use "Integer.valueOf(int)" instead of "new Integer(int)".
      • Use more efficient Long cache: Use "Long.valueOf(int)" instead of "new Long(long)".
      • Use more efficient Short cache: Use "Short.valueOf(int)" instead of "new Short(short)".

      In Java version 1.6.0_24 (vendor: Sun Microsystems Inc.), Float and Double do not implement caches, but I've made the same changes for consistency and future proofing.

      • Use "Double.valueOf(int)" instead of "new Double(double)".
      • Use "Float.valueOf(int)" instead of "new Float(float)".

      Attachments

        Activity

          People

            ggregory Gary D. Gregory
            ggregory Gary D. Gregory
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: