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灯, 水草

请输入看板名称,例如:BabyMother站内搜寻

TOP