diff --git a/jdk/src/share/classes/java/lang/doc-files/ValueBased.html b/jdk/src/share/classes/java/lang/doc-files/ValueBased.html new file mode 100644 index 00000000000..7e1ee8bbf2c --- /dev/null +++ b/jdk/src/share/classes/java/lang/doc-files/ValueBased.html @@ -0,0 +1,42 @@ + + + + Value-based Classes + + + +

Value-based Classes

+ +Some classes, such as java.util.Optional and +java.time.LocalDateTime, are value-based. Instances of a +value-based class: + + +

A program may produce unpredictable results if it attempts to distinguish two + references to equal values of a value-based class, whether directly via reference + equality or indirectly via an appeal to synchronization, identity hashing, + serialization, or any other identity-sensitive mechanism. Use of such + identity-sensitive operations on instances of value-based classes may have + unpredictable effects and should be avoided.

+ + diff --git a/jdk/src/share/classes/java/util/Optional.java b/jdk/src/share/classes/java/util/Optional.java index 10b79234b18..d471058ec16 100644 --- a/jdk/src/share/classes/java/util/Optional.java +++ b/jdk/src/share/classes/java/util/Optional.java @@ -40,6 +40,11 @@ import java.util.function.Supplier; * {@link #ifPresent(java.util.function.Consumer) ifPresent()} (execute a block * of code if the value is present). * + *

This is a value-based + * class; use of identity-sensitive operations (including reference equality + * ({@code ==}), identity hash code, or synchronization) on instances of + * {@code Optional} may have unpredictable results and should be avoided. + * * @since 1.8 */ public final class Optional { diff --git a/jdk/src/share/classes/java/util/OptionalDouble.java b/jdk/src/share/classes/java/util/OptionalDouble.java index eda306cf7d4..0efc770fa03 100644 --- a/jdk/src/share/classes/java/util/OptionalDouble.java +++ b/jdk/src/share/classes/java/util/OptionalDouble.java @@ -31,7 +31,7 @@ import java.util.function.Supplier; /** * A container object which may or may not contain a {@code double} value. * If a value is present, {@code isPresent()} will return {@code true} and - * {@code get()} will return the value. + * {@code getAsDouble()} will return the value. * *

Additional methods that depend on the presence or absence of a contained * value are provided, such as {@link #orElse(double) orElse()} @@ -39,6 +39,11 @@ import java.util.function.Supplier; * {@link #ifPresent(java.util.function.DoubleConsumer) ifPresent()} (execute a block * of code if the value is present). * + *

This is a value-based + * class; use of identity-sensitive operations (including reference equality + * ({@code ==}), identity hash code, or synchronization) on instances of + * {@code OptionalDouble} may have unpredictable results and should be avoided. + * * @since 1.8 */ public final class OptionalDouble { diff --git a/jdk/src/share/classes/java/util/OptionalInt.java b/jdk/src/share/classes/java/util/OptionalInt.java index 66478ce4713..5cb9275242b 100644 --- a/jdk/src/share/classes/java/util/OptionalInt.java +++ b/jdk/src/share/classes/java/util/OptionalInt.java @@ -31,7 +31,7 @@ import java.util.function.Supplier; /** * A container object which may or may not contain a {@code int} value. * If a value is present, {@code isPresent()} will return {@code true} and - * {@code get()} will return the value. + * {@code getAsInt()} will return the value. * *

Additional methods that depend on the presence or absence of a contained * value are provided, such as {@link #orElse(int) orElse()} @@ -39,6 +39,11 @@ import java.util.function.Supplier; * {@link #ifPresent(java.util.function.IntConsumer) ifPresent()} (execute a block * of code if the value is present). * + *

This is a value-based + * class; use of identity-sensitive operations (including reference equality + * ({@code ==}), identity hash code, or synchronization) on instances of + * {@code OptionalInt} may have unpredictable results and should be avoided. + * * @since 1.8 */ public final class OptionalInt { diff --git a/jdk/src/share/classes/java/util/OptionalLong.java b/jdk/src/share/classes/java/util/OptionalLong.java index f07cc0d3d3a..589a59fd3ae 100644 --- a/jdk/src/share/classes/java/util/OptionalLong.java +++ b/jdk/src/share/classes/java/util/OptionalLong.java @@ -31,7 +31,7 @@ import java.util.function.Supplier; /** * A container object which may or may not contain a {@code long} value. * If a value is present, {@code isPresent()} will return {@code true} and - * {@code get()} will return the value. + * {@code getAsLong()} will return the value. * *

Additional methods that depend on the presence or absence of a contained * value are provided, such as {@link #orElse(long) orElse()} @@ -39,6 +39,11 @@ import java.util.function.Supplier; * {@link #ifPresent(java.util.function.LongConsumer) ifPresent()} (execute a block * of code if the value is present). * + *

This is a value-based + * class; use of identity-sensitive operations (including reference equality + * ({@code ==}), identity hash code, or synchronization) on instances of + * {@code OptionalLong} may have unpredictable results and should be avoided. + * * @since 1.8 */ public final class OptionalLong {