JDK-4649313 : RFE: Please add 'public static Boolean Boolean.getBoolean(boolean b)'
  • Type: Enhancement
  • Component: core-libs
  • Sub-Component: java.lang
  • Affected Version: 1.4.0
  • Priority: P4
  • Status: Closed
  • Resolution: Duplicate
  • OS: windows_nt
  • CPU: x86
  • Submitted: 2002-03-08
  • Updated: 2002-03-08
  • Resolved: 2002-03-08
Related Reports
Duplicate :  
Description

Name: rmT116609			Date: 03/07/2002


FULL PRODUCT VERSION :
java version "1.4.0"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.0-b92)
Java HotSpot(TM) Client VM (build 1.4.0-b92, mixed mode)


A DESCRIPTION OF THE PROBLEM :
It would be nice to add the following convienience method to Boolean.

public static Boolean getBoolean(boolean b) {
  return (b ? Boolean.TRUE : Boolean.FALSE);
}

While not a significant piece of code, this would clean up a lot of places where this same logic happens today.  Even better it would encourage people to use the TRUE and FALSE constants rather than just creating new Booleans as they
often do today.

This bug can be reproduced always.

CUSTOMER WORKAROUND :
Currently people do one of two things

public void foo(boolean b) {
  Boolean b1 = new Boolean(b);
}

public void bar(boolean b) {
  Boolean b1 = (b ? Boolean.TRUE : Boolean.FALSE);
}

If this RFE is implemented they could instead do:

public void baz(boolean b) {
  Boolean b1 = Boolean.getBoolean(b);
}

Which has the cleanliness of foo(), but function of bar().
(Review ID: 143890) 
======================================================================

Comments
WORK AROUND Boolean.valueOf(boolean) -- iag@sfbay 2002-02-07
07-02-2002

EVALUATION This functionality was introduced in jdk1.4 as part of bug 4262398. See Boolean.valueOf(boolean). -- iag@sfbay 2002-02-07
07-02-2002