JDK-4262398 : Avoid creating new Booleans for increased operational speed
  • Type: Enhancement
  • Component: other-libs
  • Sub-Component: other
  • Affected Version: 1.2.0,1.4.0
  • Priority: P4
  • Status: Resolved
  • Resolution: Fixed
  • OS: generic,windows_nt
  • CPU: generic,x86
  • Submitted: 1999-08-13
  • Updated: 2000-10-13
  • Resolved: 2000-10-13
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
Other
1.4.0 betaFixed
Related Reports
Duplicate :  
Relates :  
Description

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) 
======================================================================

Comments
CONVERTED DATA BugTraq+ Release Management Values COMMIT TO FIX: generic merlin-beta FIXED IN: merlin merlin-beta INTEGRATED IN: merlin-beta
14-06-2004

EVALUATION Because it is possible to test objects for reference equality, this cannot be implemented as a compiler optimization. It may be appropriate to manually optimize JDK code in this manner, however. william.maddox@Eng 1999-09-09 What we should really do is to provide a static factory (Boolean.valueOf(boolean)) and promote its use in favor of the constructor (Boolean(boolean)). joshua.bloch@Eng 2000-10-03
09-09-1999