I stumbled across the source of AtomicInteger
and realized that
new AtomicInteger(0).equals(new AtomicInteger(0))
evaluates to
I would argue that because the point of an AtomicInteger
is that operations can be done atomically, it would be be hard to ensure that the two values are compared atomically, and because AtomicIntegers are generally counters, you'd get some odd behaviour.
So without ensuring that the equals
method is synchronised you wouldn't be sure that the value of the atomic integer hasn't changed by the time equals
returns. However, as the whole point of an atomic integer is not to use synchronisation, you'd end up with little benefit.