java 板


LINE

※ 引述《AmosYang (LetMeGoogleThatForYou)》之銘言: : 推 costbook:這種好東西竟然開放下載耶,感謝分享 04/30 08:30 Java 比 .Net 好就好在這些文件整理得好,在官方網站上就可輕易找到 : 推 zanyking:C#裡就很直接的給你unsafe區塊,等於是挖個窗口直接做 04/30 09:53 C# 比 Java 好就好在比較務實,以 developer 為中心 (唯一一點遺憾的就是沒有像 Java 的 throws …至少 make it optional... 讓想用的人去用,不想用的人就不要用…) : 推 james732:感謝分享 很棒的資料!! 04/30 10:30 不客氣 : → sbrhsieh:實際上JVM本身就沒有enforce final field 的不變性質在.. 04/30 15:43 : → sbrhsieh:定義該 field 的 class 內。 04/30 15:44 : → sbrhsieh:final field setter method 可以在 bytecode level 實現 04/30 15:46 sbrhsieh 提出的這點倒讓我想起來一些更有趣的事, 根據我的記憶,在 JDK 1.1, 1.2, 1.3, 1.4, 1.5 ... 一路發展下來 有一段時間其實 final field 可以用 reflection 去改其 value 接下來幾個版本又不能改 然後再下來幾個版本又變回可以改 現在最新的 Java 6 裡可以不可以改…我不知道…有空的人可以試一試 剛去問某 Java 強者這到底是在搞什麼鬼 他說有興趣的話去看 JSR-000133 Java Memory Model and Thread Specification 裡面有一章專門講 final field 我懶得去看了…有興趣的人請自行取用 XD --



※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 65.87.177.87 ※ 編輯: AmosYang 來自: 65.87.177.87 (04/30 17:03) 順藤摸瓜又摸出這個 http://www.javaspecialists.eu/archive/Issue096.html 文章有點舊,但無損其價值, 可以從 "Java 5 - "final" is not final anymore" 讀起 摘錄最重要的一段 (給與我一樣懶得去讀JSR133的人…XD) When Narve Saetre mailed me that he managed to change a final field in JDK 5 using reflection, I was hoping that a bug had crept into the JDK. However, we both felt that to be unlikely, especially such a fundamental bug. After some searching, I found the JSR-133: Java Memory Model and Thread Specification. Most of the specification is hard reading, and reminds me of my university days (I used to write like that ;-) However, JSR-133 is so important that it should be required reading for all Java programmers. (Good luck) Start with chapter 9 Final Field Semantics, on page 25. Specifically, read section 9.1.1 Post-Construction Modification of Final Fields. It makes sense to allow updates to final fields. For example, we could relax the requirement to have fields non-final in JDO. If we read section 9.1.1 carefully, we see that we should only modify final fields as part of our construction process. The use case is where we deserialize an object, and then once we have constructed the object, we initialise the final fields, before passing it on. Once we have made the object available to another thread, we should not change final fields using reflection. The result would not be predictable. It even says this: If a final field is initialized to a compile-time constant in the field declaration, changes to the final field may not be observed, since uses of that final field are replaced at compile time with the compile-time constant. This explains why our iq field stays the same, but country changes. ※ 編輯: AmosYang 來自: 65.87.177.87 (04/30 17:33) ※ 編輯: AmosYang 來自: 65.87.177.87 (04/30 17:33)







like.gif 您可能會有興趣的文章
icon.png[問題/行為] 貓晚上進房間會不會有憋尿問題
icon.pngRe: [閒聊] 選了錯誤的女孩成為魔法少女 XDDDDDDDDDD
icon.png[正妹] 瑞典 一張
icon.png[心得] EMS高領長版毛衣.墨小樓MC1002
icon.png[分享] 丹龍隔熱紙GE55+33+22
icon.png[問題] 清洗洗衣機
icon.png[尋物] 窗台下的空間
icon.png[閒聊] 双極の女神1 木魔爵
icon.png[售車] 新竹 1997 march 1297cc 白色 四門
icon.png[討論] 能從照片感受到攝影者心情嗎
icon.png[狂賀] 賀賀賀賀 賀!島村卯月!總選舉NO.1
icon.png[難過] 羨慕白皮膚的女生
icon.png閱讀文章
icon.png[黑特]
icon.png[問題] SBK S1安裝於安全帽位置
icon.png[分享] 舊woo100絕版開箱!!
icon.pngRe: [無言] 關於小包衛生紙
icon.png[開箱] E5-2683V3 RX480Strix 快睿C1 簡單測試
icon.png[心得] 蒼の海賊龍 地獄 執行者16PT
icon.png[售車] 1999年Virage iO 1.8EXi
icon.png[心得] 挑戰33 LV10 獅子座pt solo
icon.png[閒聊] 手把手教你不被桶之新手主購教學
icon.png[分享] Civic Type R 量產版官方照無預警流出
icon.png[售車] Golf 4 2.0 銀色 自排
icon.png[出售] Graco提籃汽座(有底座)2000元誠可議
icon.png[問題] 請問補牙材質掉了還能再補嗎?(台中半年內
icon.png[問題] 44th 單曲 生寫竟然都給重複的啊啊!
icon.png[心得] 華南紅卡/icash 核卡
icon.png[問題] 拔牙矯正這樣正常嗎
icon.png[贈送] 老莫高業 初業 102年版
icon.png[情報] 三大行動支付 本季掀戰火
icon.png[寶寶] 博客來Amos水蠟筆5/1特價五折
icon.pngRe: [心得] 新鮮人一些面試分享
icon.png[心得] 蒼の海賊龍 地獄 麒麟25PT
icon.pngRe: [閒聊] (君の名は。雷慎入) 君名二創漫畫翻譯
icon.pngRe: [閒聊] OGN中場影片:失蹤人口局 (英文字幕)
icon.png[問題] 台灣大哥大4G訊號差
icon.png[出售] [全國]全新千尋侘草LED燈, 水草

請輸入看板名稱,例如:Boy-Girl站內搜尋

TOP