The right way to do equals and hashcode of objects held by AtomicReference
问题 AtomicReference doesn't work with Objects.equals() and Objects.hash() . AtomicReference<String> ref1 = new AtomicReference<>("hi"); AtomicReference<String> ref2 = new AtomicReference<>("hi"); System.out.println(Objects.equals(ref1, ref2)); //false System.out.println(Objects.equals(ref1.get(), ref2.get())); //true but potentially not thread safe System.out.println(Objects.hash(ref1) == Objects.hash(ref2)); //false System.out.println(Objects.hash(ref1.get()) == Objects.hash(ref2.get())); //true