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

Avoid creating new Booleans for increased operational speed

XMLWordPrintable

    • beta
    • generic, x86
    • generic, windows_nt



      Name: krT82822 Date: 08/13/99


      This isn't really a feature request, more of an optimization
      request. Its also closely related to bug #4206052

      There is no need for more than two instances of Boolean
      at any time during the life of the VM. They are of course
      Boolean.TRUE and Boolean.FALSE. A quick search for the string
      "new Boolean" turned up several dozen instances where Java creates
      a new object when a simple TRUE or FALSE would do.

      In general:

      - "new Boolean(true)" & "new Boolean(false)" should be replaced
        with "Boolean.TRUE" & "Boolean.FALSE" respectively.
      - "new Boolean(b)" where b is a boolean expression should be
        replaced with "b ? Boolean.TRUE : Boolean.FALSE".
      - "new Boolean(s)" where s is a String should be replaced with
        "Boolean.valueOf(s)", especially if the improvements listed
        in bug #4206052 are implemented.

      If these improvements are made you will see an increase in speed
      since no object needs to be created and a lighter load on the
      garbage collector due to fewer objects.
      (Review ID: 93906)
      ======================================================================

            stewilso Steve Wilson (Inactive)
            kryansunw Kevin Ryan (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: