Is String s = “foobar” atomic?

后端 未结 2 452
天涯浪人
天涯浪人 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:45

    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:

    String s = string_a + string_b;
    

提交回复
热议问题