< prev index next >

src/java.base/share/classes/java/lang/Boolean.java

Print this page

  8  * particular file as subject to the "Classpath" exception as provided
  9  * by Oracle in the LICENSE file that accompanied this code.
 10  *
 11  * This code is distributed in the hope that it will be useful, but WITHOUT
 12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 14  * version 2 for more details (a copy is included in the LICENSE file that
 15  * accompanied this code).
 16  *
 17  * You should have received a copy of the GNU General Public License version
 18  * 2 along with this work; if not, write to the Free Software Foundation,
 19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 20  *
 21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
 22  * or visit www.oracle.com if you need additional information or have any
 23  * questions.
 24  */
 25 
 26 package java.lang;
 27 

 28 import jdk.internal.vm.annotation.IntrinsicCandidate;
 29 
 30 import java.lang.constant.Constable;
 31 import java.lang.constant.ConstantDesc;
 32 import java.lang.constant.ConstantDescs;
 33 import java.lang.constant.DynamicConstantDesc;
 34 import java.util.Optional;
 35 
 36 import static java.lang.constant.ConstantDescs.BSM_GET_STATIC_FINAL;
 37 import static java.lang.constant.ConstantDescs.CD_Boolean;
 38 
 39 /**
 40  * The {@code Boolean} class is the {@linkplain
 41  * java.lang##wrapperClass wrapper class} for values of the primitive
 42  * type {@code boolean}. An object of type {@code Boolean} contains a
 43  * single field whose type is {@code boolean}.
 44  *
 45  * <p>In addition, this class provides many methods for
 46  * converting a {@code boolean} to a {@code String} and a
 47  * {@code String} to a {@code boolean}, as well as other
 48  * constants and methods useful when dealing with a
 49  * {@code boolean}.
 50  *
 51  * <p>This is a <a href="{@docRoot}/java.base/java/lang/doc-files/ValueBased.html">value-based</a>
 52  * class; programmers should treat instances that are
 53  * {@linkplain #equals(Object) equal} as interchangeable and should not
 54  * use instances for synchronization, or unpredictable behavior may
 55  * occur. For example, in a future release, synchronization may fail.
 56  *
 57  * @author  Arthur van Hoff
 58  * @since   1.0
 59  */

 60 @jdk.internal.ValueBased
 61 public final class Boolean implements java.io.Serializable,
 62                                       Comparable<Boolean>, Constable
 63 {
 64     /**
 65      * The {@code Boolean} object corresponding to the primitive
 66      * value {@code true}.
 67      */
 68     public static final Boolean TRUE = new Boolean(true);
 69 
 70     /**
 71      * The {@code Boolean} object corresponding to the primitive
 72      * value {@code false}.
 73      */
 74     public static final Boolean FALSE = new Boolean(false);
 75 
 76     /**
 77      * The Class object representing the primitive type boolean.
 78      *
 79      * @since   1.1

158     @IntrinsicCandidate
159     public boolean booleanValue() {
160         return value;
161     }
162 
163     /**
164      * Returns a {@code Boolean} instance representing the specified
165      * {@code boolean} value.  If the specified {@code boolean} value
166      * is {@code true}, this method returns {@code Boolean.TRUE};
167      * if it is {@code false}, this method returns {@code Boolean.FALSE}.
168      * If a new {@code Boolean} instance is not required, this method
169      * should generally be used in preference to the constructor
170      * {@link #Boolean(boolean)}, as this method is likely to yield
171      * significantly better space and time performance.
172      *
173      * @param  b a boolean value.
174      * @return a {@code Boolean} instance representing {@code b}.
175      * @since  1.4
176      */
177     @IntrinsicCandidate

178     public static Boolean valueOf(boolean b) {
179         return (b ? TRUE : FALSE);
180     }
181 
182     /**
183      * Returns a {@code Boolean} with a value represented by the
184      * specified string.  The {@code Boolean} returned represents a
185      * true value if the string argument is not {@code null}
186      * and is equal, ignoring case, to the string {@code "true"}.
187      * Otherwise, a false value is returned, including for a null
188      * argument.
189      *
190      * @param   s   a string.
191      * @return  the {@code Boolean} value represented by the string.
192      */
193     public static Boolean valueOf(String s) {
194         return parseBoolean(s) ? TRUE : FALSE;
195     }
196 
197     /**

  8  * particular file as subject to the "Classpath" exception as provided
  9  * by Oracle in the LICENSE file that accompanied this code.
 10  *
 11  * This code is distributed in the hope that it will be useful, but WITHOUT
 12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 14  * version 2 for more details (a copy is included in the LICENSE file that
 15  * accompanied this code).
 16  *
 17  * You should have received a copy of the GNU General Public License version
 18  * 2 along with this work; if not, write to the Free Software Foundation,
 19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 20  *
 21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
 22  * or visit www.oracle.com if you need additional information or have any
 23  * questions.
 24  */
 25 
 26 package java.lang;
 27 
 28 import jdk.internal.value.DeserializeConstructor;
 29 import jdk.internal.vm.annotation.IntrinsicCandidate;
 30 
 31 import java.lang.constant.Constable;

 32 import java.lang.constant.ConstantDescs;
 33 import java.lang.constant.DynamicConstantDesc;
 34 import java.util.Optional;
 35 



 36 /**
 37  * The {@code Boolean} class is the {@linkplain
 38  * java.lang##wrapperClass wrapper class} for values of the primitive
 39  * type {@code boolean}. An object of type {@code Boolean} contains a
 40  * single field whose type is {@code boolean}.
 41  *
 42  * <p>In addition, this class provides many methods for
 43  * converting a {@code boolean} to a {@code String} and a
 44  * {@code String} to a {@code boolean}, as well as other
 45  * constants and methods useful when dealing with a
 46  * {@code boolean}.
 47  *
 48  * <p>This is a <a href="{@docRoot}/java.base/java/lang/doc-files/ValueBased.html">value-based</a>
 49  * class; programmers should treat instances that are
 50  * {@linkplain #equals(Object) equal} as interchangeable and should not
 51  * use instances for synchronization, or unpredictable behavior may
 52  * occur. For example, in a future release, synchronization may fail.
 53  *
 54  * @author  Arthur van Hoff
 55  * @since   1.0
 56  */
 57 @jdk.internal.MigratedValueClass
 58 @jdk.internal.ValueBased
 59 public final class Boolean implements java.io.Serializable,
 60                                       Comparable<Boolean>, Constable
 61 {
 62     /**
 63      * The {@code Boolean} object corresponding to the primitive
 64      * value {@code true}.
 65      */
 66     public static final Boolean TRUE = new Boolean(true);
 67 
 68     /**
 69      * The {@code Boolean} object corresponding to the primitive
 70      * value {@code false}.
 71      */
 72     public static final Boolean FALSE = new Boolean(false);
 73 
 74     /**
 75      * The Class object representing the primitive type boolean.
 76      *
 77      * @since   1.1

156     @IntrinsicCandidate
157     public boolean booleanValue() {
158         return value;
159     }
160 
161     /**
162      * Returns a {@code Boolean} instance representing the specified
163      * {@code boolean} value.  If the specified {@code boolean} value
164      * is {@code true}, this method returns {@code Boolean.TRUE};
165      * if it is {@code false}, this method returns {@code Boolean.FALSE}.
166      * If a new {@code Boolean} instance is not required, this method
167      * should generally be used in preference to the constructor
168      * {@link #Boolean(boolean)}, as this method is likely to yield
169      * significantly better space and time performance.
170      *
171      * @param  b a boolean value.
172      * @return a {@code Boolean} instance representing {@code b}.
173      * @since  1.4
174      */
175     @IntrinsicCandidate
176     @DeserializeConstructor
177     public static Boolean valueOf(boolean b) {
178         return (b ? TRUE : FALSE);
179     }
180 
181     /**
182      * Returns a {@code Boolean} with a value represented by the
183      * specified string.  The {@code Boolean} returned represents a
184      * true value if the string argument is not {@code null}
185      * and is equal, ignoring case, to the string {@code "true"}.
186      * Otherwise, a false value is returned, including for a null
187      * argument.
188      *
189      * @param   s   a string.
190      * @return  the {@code Boolean} value represented by the string.
191      */
192     public static Boolean valueOf(String s) {
193         return parseBoolean(s) ? TRUE : FALSE;
194     }
195 
196     /**
< prev index next >