???????Java????????final
???????????? ???????[ 2013/3/21 10:35:29 ] ????????
????????final????????????????????????int???????????????????????дfinal????????????????????????????????????????
????1???????????????final??????????????д???????????????????????????????????????????????????????????????????????
????????????????????????????????A???writerOne()???????????????B???writerTwo()???????????????C???reader ()????????????????????????????
??????????У?1???final???д??2??????final????????????????д??3???????????????????????????????????????????????1?????3????????2??3???????????
????JMM????????????C?????????д???A????????ж?final?????????????д????C??????????????±?0????1????д???B??????????д???????C??????????????????????JMM????????B??д???????C????????д???B??????C??????????????????????н??????????
??????????????????C????д???B??????????д??д???B??????C???????????????lock??volatile???????????????
???????final???ò???????????“???”
?????????????????дfinal????????????????????????????????????????????????????????????final?????????????б????????????????????????Ч?????????????????????????????????????????????????????????????????????????ò????????????“???”?????????????????????????????????
public class FinalReferenceEscapeExample {
final int i;
static FinalReferenceEscapeExample obj;
public FinalReferenceEscapeExample () {
i = 1; //1дfinal??
obj = this; //2 this???????“???”
}
public static void writer() {
new FinalReferenceEscapeExample ();
}
public static void reader {
if (obj != null) { //3
int temp = obj.i; //4
}
}
}
??????
???·???
??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???·???????·
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11