< 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

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

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     /**

  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

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