< prev index next > src/java.base/share/classes/java/util/OptionalLong.java
Print this page
* (returns a default value if no value is present) and
* {@link #ifPresent(LongConsumer) ifPresent()} (performs an
* action if a value is present).
*
* <p>This is a <a href="{@docRoot}/java.base/java/lang/doc-files/ValueBased.html">value-based</a>
- * class; programmers should treat instances that are
- * {@linkplain #equals(Object) equal} as interchangeable and should not
- * use instances for synchronization, or unpredictable behavior may
- * occur. For example, in a future release, synchronization may fail.
+ * class; programmers should treat instances that are {@linkplain #equals(Object) equal}
+ * as interchangeable and should not use instances for synchronization, mutexes, or
+ * with {@linkplain java.lang.ref.Reference object references}.
+ *
+ * <div class="preview-block">
+ * <div class="preview-comment">
+ * When preview features are enabled, {@code OptionalLong} is a {@linkplain Class#isValue value class}.
+ * Use of value class instances for synchronization, mutexes, or with
+ * {@linkplain java.lang.ref.Reference object references} result in
+ * {@link IdentityException}.
+ * </div>
+ * </div>
*
* @apiNote
* {@code OptionalLong} is primarily intended for use as a method return type where
* there is a clear need to represent "no result." A variable whose type is
* {@code OptionalLong} should never itself be {@code null}; it should always point
* to an {@code OptionalLong} instance.
*
* @since 1.8
*/
@jdk.internal.ValueBased
+ @jdk.internal.MigratedValueClass
public final class OptionalLong {
/**
* Common instance for {@code empty()}.
*/
private static final OptionalLong EMPTY = new OptionalLong();
< prev index next >