Is String s = “foobar” atomic?

后端 未结 2 453
天涯浪人
天涯浪人 2021-01-01 19:54

Is String s = \"foobar\"; atomic?

Assigning a object-reference should be, but I\'m no really sure.

Thanks.

2条回答
  •  梦谈多话
    2021-01-01 20:44

    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

提交回复
热议问题