java - 我们可以将 Java 中的最终重新排序规则视为发生在规则之前吗?
问题描述
Java中存在两条最终记录规则,如下:
a write to final field in constructor
并且the constructed instance reference is assigned to variable afterwards
不能重新排序read a instance reference
并且read the final field in the instance afterwards
不能重新排序
我们可以将上述规则视为发生之前的规则吗?
a write to final field in constructor
发生之前the constructed instance reference is assigned to variable afterwards
read a instance reference
发生之前read the final field in the instance afterwards
我认为发生在规则之前的语义更强。
解决方案
最后,在我的理解中,final关键字和happens-before规则的语义保证属于不同的类别。上述推导是错误的和不必要的。
推荐阅读
- python - 如何修复 djangos 的 decotators 错误:包装类必须子类化 ModelAdmin
- powershell - 试图弄清楚如何使用 Powershell 在 Exchange 用户的别名中插入首字母+姓氏
- java - 尽管原始文件有效,但从服务器下载的 PDF 无效
- javascript - 将 JSON 结果从 AJAX 传递到 HTML
- java - 是否必须拥有相同版本的 jdk 和 jre?
- babeljs - babel-plugin-transform-duplicate-keys 有什么用?
- neo4j - 获取具有特定节点属性值的最新节点
- reactjs - 为什么比较当前道具与具有相同值的 nextProps 会返回 false?
- php - 从两个表中选择数据,将其插入到新表中?(SQL/PHP)
- arrays - Angular 类中的数组数组