Java this escape:修订间差异

来自WHY42
Riguz留言 | 贡献
建立內容為「<syntaxhighlight lang="java"> public FinalFieldExample() { // bad! x = 3; y = 4; // bad construction - allowing this to escape global.obj = this; } </synt…」的新頁面
 
Riguz留言 | 贡献
Riguz移动页面Java:this逸出Java this escape,不留重定向
 
(未显示同一用户的1个中间版本)
第9行: 第9行:
then threads that read the reference to this from global.obj are not guaranteed to see 3 for x.
then threads that read the reference to this from global.obj are not guaranteed to see 3 for x.


[[Category:Java]]
[[Category:Concurrency]]

2023年12月19日 (二) 06:55的最新版本

public FinalFieldExample() { // bad!
  x = 3;
  y = 4;
  // bad construction - allowing this to escape
  global.obj = this;
}

then threads that read the reference to this from global.obj are not guaranteed to see 3 for x.