< prev index next >

src/java.base/share/classes/java/util/OptionalDouble.java

Print this page
*** 40,24 ***
   * (returns a default value if no value is present) and
   * {@link #ifPresent(DoubleConsumer) 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.
   *
   * @apiNote
   * {@code OptionalDouble} 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 OptionalDouble} should never itself be {@code null}; it should always point
   * to an {@code OptionalDouble} instance.
   *
   * @since 1.8
   */
  @jdk.internal.ValueBased
  public final class OptionalDouble {
      /**
       * Common instance for {@code empty()}.
       */
      private static final OptionalDouble EMPTY = new OptionalDouble();
--- 40,33 ---
   * (returns a default value if no value is present) and
   * {@link #ifPresent(DoubleConsumer) 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, mutexes, or
!  * with {@linkplain java.lang.ref.Reference object references}.
!  *
+  * <div class="preview-block">
+  *      <div class="preview-comment">
+  *          When preview features are enabled, {@code OptionalDouble} 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 OptionalDouble} 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 OptionalDouble} should never itself be {@code null}; it should always point
   * to an {@code OptionalDouble} instance.
   *
   * @since 1.8
   */
  @jdk.internal.ValueBased
+ @jdk.internal.MigratedValueClass
  public final class OptionalDouble {
      /**
       * Common instance for {@code empty()}.
       */
      private static final OptionalDouble EMPTY = new OptionalDouble();
< prev index next >