| [ Web Proxy ] |
| Viewing: https://docs.oracle.com/en/java/javase/16/docs/api/java.base/java/lang/doc-files/ValueBased.html | [Back] [Original] |
java.lang.Integer and
java.time.LocalDate, are value-based.
A value-based class has the following properties:
equals, hashCode,
and toString compute their results solely from the values
of the class's instance fields (and the members of the objects they
reference), not from the instance's identity;x and
y that are equal according to equals() produces no
visible change in the behavior of the class's methods;equals(), they may also be
equal according to ==;Object or a hierarchy of
abstract classes that declare no instance fields or instance initializers
and whose constructors are empty.When two instances of a value-based class are equal (according to `equals`), a program should not attempt to distinguish between their identities, whether directly via reference equality or indirectly via an appeal to synchronization, identity hashing, serialization, or any other identity-sensitive mechanism.
Synchronization on instances of value-based classes is strongly discouraged, because the programmer cannot guarantee exclusive ownership of the associated monitor.
Identity-related behavior of value-based classes may change in a future release. For example, synchronization may fail.
Report a bug or suggest an enhancement
For further API reference and developer documentation see the Java SE Documentation, which contains more detailed, developer-targeted descriptions with conceptual overviews, definitions of terms, workarounds, and working code examples.
Java is a trademark or registered trademark of Oracle and/or its affiliates in the US and other countries.
Copyright © 1993, 2021, Oracle and/or its affiliates, 500 Oracle Parkway, Redwood Shores, CA 94065 USA.
All rights reserved. Use is subject to license terms and the documentation redistribution policy.
| Web Proxy Viewer | New URL | Original Page |