为什么不应在 LocalDateTime 实例上使用身份敏感操作(==、身份哈希码或同步)

why shouldn't use identity-sensitive operations (==, identity hash code, or synchronization) on instances of LocalDateTime

我目前正在研究 java.time API 我在 Java LocalDateTime Documentation

上遇到了以下短语

This is a value-based class; use of identity-sensitive operations (including reference equality (==), identity hash code, or synchronization) on instances of LocalDateTime may have unpredictable results and should be avoided. The equals method should be used for comparisons.

所以,我只是想知道,为什么不建议在 LocalDateTime 实例上使用身份敏感操作(包括引用相等性 (==)、身份哈希码或同步)?

在 javadoc 上,"value-based" 有一个 link 到 this page,它更详细地解释了它的含义。

其余部分基本上是说您不应该对实例身份做出任何假设。例如,LocalDate.of(y, m, d) 调用两次可能 return 是同一个实例,也可能不是。

那个宣传语可能与 Java 10 一起出现,它将介绍 value objects