39 * value are provided, such as {@link #orElse(long) orElse()}
40 * (returns a default value if no value is present) and
41 * {@link #ifPresent(LongConsumer) ifPresent()} (performs an
42 * action if a value is present).
43 *
44 * <p>This is a <a href="{@docRoot}/java.base/java/lang/doc-files/ValueBased.html">value-based</a>
45 * class; programmers should treat instances that are
46 * {@linkplain #equals(Object) equal} as interchangeable and should not
47 * use instances for synchronization, or unpredictable behavior may
48 * occur. For example, in a future release, synchronization may fail.
49 *
50 * @apiNote
51 * {@code OptionalLong} is primarily intended for use as a method return type where
52 * there is a clear need to represent "no result." A variable whose type is
53 * {@code OptionalLong} should never itself be {@code null}; it should always point
54 * to an {@code OptionalLong} instance.
55 *
56 * @since 1.8
57 */
58 @jdk.internal.ValueBased
59 public final class OptionalLong {
60 /**
61 * Common instance for {@code empty()}.
62 */
63 private static final OptionalLong EMPTY = new OptionalLong();
64
65 /**
66 * If true then the value is present, otherwise indicates no value is present
67 */
68 private final boolean isPresent;
69 private final long value;
70
71 /**
72 * Construct an empty instance.
73 *
74 * @implNote generally only one empty instance, {@link OptionalLong#EMPTY},
75 * should exist per VM.
76 */
77 private OptionalLong() {
78 this.isPresent = false;
|
39 * value are provided, such as {@link #orElse(long) orElse()}
40 * (returns a default value if no value is present) and
41 * {@link #ifPresent(LongConsumer) ifPresent()} (performs an
42 * action if a value is present).
43 *
44 * <p>This is a <a href="{@docRoot}/java.base/java/lang/doc-files/ValueBased.html">value-based</a>
45 * class; programmers should treat instances that are
46 * {@linkplain #equals(Object) equal} as interchangeable and should not
47 * use instances for synchronization, or unpredictable behavior may
48 * occur. For example, in a future release, synchronization may fail.
49 *
50 * @apiNote
51 * {@code OptionalLong} is primarily intended for use as a method return type where
52 * there is a clear need to represent "no result." A variable whose type is
53 * {@code OptionalLong} should never itself be {@code null}; it should always point
54 * to an {@code OptionalLong} instance.
55 *
56 * @since 1.8
57 */
58 @jdk.internal.ValueBased
59 @jdk.internal.MigratedValueClass
60 public final class OptionalLong {
61 /**
62 * Common instance for {@code empty()}.
63 */
64 private static final OptionalLong EMPTY = new OptionalLong();
65
66 /**
67 * If true then the value is present, otherwise indicates no value is present
68 */
69 private final boolean isPresent;
70 private final long value;
71
72 /**
73 * Construct an empty instance.
74 *
75 * @implNote generally only one empty instance, {@link OptionalLong#EMPTY},
76 * should exist per VM.
77 */
78 private OptionalLong() {
79 this.isPresent = false;
|