我在官方文档中找不到任何信息。我知道Boolean.hashCode(boolean b)
返回两个素数 1231 和 1237 分别表示 true 和 false。我希望在 AtomicBoolean
中有类似的实现。但在反编译的类文件中,它似乎调用 public native int hashCode();
的Object
- 这是否意味着它将返回内存位置?
最佳答案
package summary告诉为什么 hashCode
没有被 AtomicBoolean
覆盖:
Atomic classes are not general purpose replacements for java.lang.Integer and related classes. They do not define methods such as
equals
,hashCode
andcompareTo
. (Because atomic variables are expected to be mutated, they are poor choices for hash table keys.)
这是否意味着它将返回内存位置?
这取决于您使用的 JVM,但是,是的,它通常是从内存地址派生的。其他 JVM 可能只使用随机数。
关于java - AtomicBoolean 的 hashCode 是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41449690/