Atomic variables such as AtomicInteger and AtomicReference support concurrent updates, but equals() does not compare their stored payloads. Read the values explicitly with get() when value comparison is actually appropriate. section 7.2
var v1 = new AtomicInteger(1); var v2 = new AtomicInteger(1); System.out.println(v1.equals(v2)); #1 System.out.println(v1.get() == v2.get()); #2
Compare the wrapper objects with equals(), then compare their current stored values with get(). The second comparison expresses payload equality. section 7.2
Use this rule cautiously:
- Do not assume two atomic variables are equal because their values matched once; concurrent updates can change that relationship immediately afterward. section 7.2
- Compare atomic values only when updates have finished, or when the application explicitly accepts the timing of the comparison. section 7.2
















