字符串s =" foobar"原子? [英] Is String s = "foobar" atomic?
本文介绍了字符串s =" foobar"原子?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是 String s =foobar;
atomic?
分配对象引用应该是,但是我不太确定。
Assigning a object-reference should be, but I'm no really sure.
谢谢。
推荐答案
<强>是。所有引用赋值在java中都是原子的。
Yes. All reference assignments are atomic in java.
请注意复合语句,如 String s = new String(foobar)
不是原子的,因为它包含一个对象创建,然后是一个单独的赋值。
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.
还要注意对long和double变量的赋值可能不是原子的 ,来自 JLS-17.7
Also note that "assignments to long and double variables may not be atomic", from JLS-17.7
这篇关于字符串s =" foobar"原子?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文