???????Java????????final
???????????? ???????[ 2013/3/21 10:35:29 ] ????????
??????????У?д??????????????????????????????????????B????????????????i??????????????дfinal??????????дfinal????????????“???”??????????????????B?????????final????????????????
????дfinal????????????????????????????????????????????????final???????????????????????????????????????????????????????B“????”????????obj????????obj??????й??????????????i??д???????????????????????????2?????д???????i????
??????final????????????
??????final???????????????£?
?????? ?????????У????ζ?????????????ζ???????????final??JMM???????????????????????????????????????????????????????????????final????????????????LoadLoad?????
???????ζ?????????????ζ???????????final???????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????alpha????????????????????????????????????????
????reader()??????????????????
????1?????ζ????????obj??
????2?????ζ????????obj????????????j??
????3?????ζ????????obj???????final??i??
???????????????д???A??з????κ?????????????????????????????????????У????????????????????
??????????У?????????????????????????????????????????????????????????????б?д???Aд??????????????????????????final???????????????????final??????“???”???????????????????final???????A????????????????????????????????
??????final???????????????????????????????final?????????????????????final??????????á??????????????У?????????ò??null?????????????final??????????A????????????
???????final????????????
?????????????????final????????????????????????????????final?????????????????????Ч????
?????????????????
public class FinalReferenceExample {
final int[] intArray; //final??????????
static FinalReferenceExample obj;
public FinalReferenceExample () { //??????
intArray = new int[1]; //1
intArray[0] = 1; //2
}
public static void writerOne () { //д???A???
obj = new FinalReferenceExample (); //3
}
public static void writerTwo () { //д???B???
obj.intArray[0] = 2; //4
}
public static void reader () { //?????C???
if (obj != null) { //5
int temp1 = obj.intArray[0]; //6
}
}
}
??????
???·???
??????????????????
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