Yes. All reference assignments are atomic in java.
Just note that a composite statement like String s = new String("foobar") is not atomic, because it comprises of an object creation and then an assignment separately.
Also note that "assignments to long and double variables may not be atomic", from JLS-17.7
Yes. All reference assignments are atomic in java.
Just note that a composite statement like
String s = new String("foobar")
is not atomic, because it comprises of an object creation and then an assignment separately.Also note that "assignments to long and double variables may not be atomic", from JLS-17.7
Yes, but if you're worried about race conditions, you should at least be aware of 'synchronized' methods/blocks.
And note that this is not atomic because it contains two operations: