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.ConstantDescs;
32 import java.lang.constant.DynamicConstantDesc;
33 import java.util.Optional;
34
35 /**
36 * The {@code Boolean} class is the {@linkplain
37 * java.lang##wrapperClass wrapper class} for values of the primitive
38 * type {@code boolean}. An object of type {@code Boolean} contains a
39 * single field whose type is {@code boolean}.
40 *
41 * <p>In addition, this class provides many methods for
42 * converting a {@code boolean} to a {@code String} and a
43 * {@code String} to a {@code boolean}, as well as other
44 * constants and methods useful when dealing with a
45 * {@code boolean}.
46 *
47 * <p>This is a <a href="{@docRoot}/java.base/java/lang/doc-files/ValueBased.html">value-based</a>
48 * class; programmers should treat instances that are
49 * {@linkplain #equals(Object) equal} as interchangeable and should not
50 * use instances for synchronization, or unpredictable behavior may
51 * occur. For example, in a future release, synchronization may fail.
52 *
53 * @author Arthur van Hoff
54 * @since 1.0
55 */
56 @jdk.internal.ValueBased
57 public final class Boolean implements java.io.Serializable,
58 Comparable<Boolean>, Constable
59 {
60 /**
61 * The {@code Boolean} object corresponding to the primitive
62 * value {@code true}.
63 */
64 public static final Boolean TRUE = new Boolean(true);
65
66 /**
67 * The {@code Boolean} object corresponding to the primitive
68 * value {@code false}.
69 */
70 public static final Boolean FALSE = new Boolean(false);
71
72 /**
73 * The Class object representing the primitive type boolean.
74 *
75 * @since 1.1
153 @IntrinsicCandidate
154 public boolean booleanValue() {
155 return value;
156 }
157
158 /**
159 * Returns a {@code Boolean} instance representing the specified
160 * {@code boolean} value. If the specified {@code boolean} value
161 * is {@code true}, this method returns {@code Boolean.TRUE};
162 * if it is {@code false}, this method returns {@code Boolean.FALSE}.
163 * If a new {@code Boolean} instance is not required, this method
164 * should generally be used in preference to the constructor
165 * {@link #Boolean(boolean)}, as this method is likely to yield
166 * significantly better space and time performance.
167 *
168 * @param b a boolean value.
169 * @return a {@code Boolean} instance representing {@code b}.
170 * @since 1.4
171 */
172 @IntrinsicCandidate
173 public static Boolean valueOf(boolean b) {
174 return (b ? TRUE : FALSE);
175 }
176
177 /**
178 * Returns a {@code Boolean} with a value represented by the
179 * specified string. The {@code Boolean} returned represents a
180 * true value if the string argument is not {@code null}
181 * and is equal, ignoring case, to the string {@code "true"}.
182 * Otherwise, a false value is returned, including for a null
183 * argument.
184 *
185 * @param s a string.
186 * @return the {@code Boolean} value represented by the string.
187 */
188 public static Boolean valueOf(String s) {
189 return parseBoolean(s) ? TRUE : FALSE;
190 }
191
192 /**
193 * Returns a {@code String} object representing the specified
194 * boolean. If the specified boolean is {@code true}, then
|
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.misc.PreviewFeatures;
29 import jdk.internal.value.DeserializeConstructor;
30 import jdk.internal.vm.annotation.IntrinsicCandidate;
31
32 import java.lang.constant.Constable;
33 import java.lang.constant.ConstantDescs;
34 import java.lang.constant.DynamicConstantDesc;
35 import java.util.Optional;
36
37 /**
38 * The {@code Boolean} class is the {@linkplain
39 * java.lang##wrapperClass wrapper class} for values of the primitive
40 * type {@code boolean}. An object of type {@code Boolean} contains a
41 * single field whose type is {@code boolean}.
42 *
43 * <p>In addition, this class provides many methods for
44 * converting a {@code boolean} to a {@code String} and a
45 * {@code String} to a {@code boolean}, as well as other
46 * constants and methods useful when dealing with a
47 * {@code boolean}.
48 *
49 * <p>This is a <a href="{@docRoot}/java.base/java/lang/doc-files/ValueBased.html">value-based</a>
50 * class; programmers should treat instances that are {@linkplain #equals(Object) equal}
51 * as interchangeable and should not use instances for synchronization, mutexes, or
52 * with {@linkplain java.lang.ref.Reference object references}.
53 *
54 * <div class="preview-block">
55 * <div class="preview-comment">
56 * When preview features are enabled, {@code Boolean} is a {@linkplain Class#isValue value class}.
57 * Use of value class instances for synchronization, mutexes, or with
58 * {@linkplain java.lang.ref.Reference object references} result in
59 * {@link IdentityException}.
60 * </div>
61 * </div>
62 *
63 * @author Arthur van Hoff
64 * @since 1.0
65 */
66 @jdk.internal.MigratedValueClass
67 @jdk.internal.ValueBased
68 public final class Boolean implements java.io.Serializable,
69 Comparable<Boolean>, Constable
70 {
71 /**
72 * The {@code Boolean} object corresponding to the primitive
73 * value {@code true}.
74 */
75 public static final Boolean TRUE = new Boolean(true);
76
77 /**
78 * The {@code Boolean} object corresponding to the primitive
79 * value {@code false}.
80 */
81 public static final Boolean FALSE = new Boolean(false);
82
83 /**
84 * The Class object representing the primitive type boolean.
85 *
86 * @since 1.1
164 @IntrinsicCandidate
165 public boolean booleanValue() {
166 return value;
167 }
168
169 /**
170 * Returns a {@code Boolean} instance representing the specified
171 * {@code boolean} value. If the specified {@code boolean} value
172 * is {@code true}, this method returns {@code Boolean.TRUE};
173 * if it is {@code false}, this method returns {@code Boolean.FALSE}.
174 * If a new {@code Boolean} instance is not required, this method
175 * should generally be used in preference to the constructor
176 * {@link #Boolean(boolean)}, as this method is likely to yield
177 * significantly better space and time performance.
178 *
179 * @param b a boolean value.
180 * @return a {@code Boolean} instance representing {@code b}.
181 * @since 1.4
182 */
183 @IntrinsicCandidate
184 @DeserializeConstructor
185 public static Boolean valueOf(boolean b) {
186 if (!PreviewFeatures.isEnabled()) {
187 return (b ? TRUE : FALSE);
188 }
189 return new Boolean(b);
190 }
191
192 /**
193 * Returns a {@code Boolean} with a value represented by the
194 * specified string. The {@code Boolean} returned represents a
195 * true value if the string argument is not {@code null}
196 * and is equal, ignoring case, to the string {@code "true"}.
197 * Otherwise, a false value is returned, including for a null
198 * argument.
199 *
200 * @param s a string.
201 * @return the {@code Boolean} value represented by the string.
202 */
203 public static Boolean valueOf(String s) {
204 return parseBoolean(s) ? TRUE : FALSE;
205 }
206
207 /**
208 * Returns a {@code String} object representing the specified
209 * boolean. If the specified boolean is {@code true}, then
|