< prev index next >

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

Print this page
*** 1,7 ***
  /*
!  * Copyright (c) 2012, 2020, Oracle and/or its affiliates. All rights reserved.
   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   *
   * This code is free software; you can redistribute it and/or modify it
   * under the terms of the GNU General Public License version 2 only, as
   * published by the Free Software Foundation.  Oracle designates this
--- 1,7 ---
  /*
!  * Copyright (c) 2012, 2026, Oracle and/or its affiliates. All rights reserved.
   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   *
   * This code is free software; you can redistribute it and/or modify it
   * under the terms of the GNU General Public License version 2 only, as
   * published by the Free Software Foundation.  Oracle designates this

*** 40,25 ***
   * (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 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 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
! public final /*value*/ class OptionalDouble {
      /**
       * Common instance for {@code empty()}.
       */
      private static final OptionalDouble EMPTY = new OptionalDouble();
  
< prev index next >