Why are two AtomicIntegers never equal?

前端 未结 9 2138
日久生厌
日久生厌 2020-12-01 18:02

I stumbled across the source of AtomicInteger and realized that

new AtomicInteger(0).equals(new AtomicInteger(0))

evaluates to

9条回答
  •  粉色の甜心
    2020-12-01 18:33

    AtomicInteger inherits from Object and not Integer, and it uses standard reference equality check.

    If you google you will find this discussion of this exact case.

提交回复
热议问题