当前位置:网站首页>final 原理
final 原理
2022-06-13 09:00:00 【Q z1997】
设置 final 变量的原理
理解了 volatile 原理,再对比 final 的实现就比较简单了
public class TestFinal {
final int a = 20;
}
字节码
0: aload_0
1: invokespecial #1 // Method java/lang/Object."<init>":()V
4: aload_0
5: bipush 20
7: putfield #2 // Field a:I
<-- 写屏障
10: return
发现 final 变量的赋值也会通过 putfield 指令来完成,同样在这条指令之后也会加入写屏障,保证在其它线程读到它的值时不会出现为 0 的情况
获取 final 变量的原理
不用使用final (低于short)
使用final(低于short)
加 final 使用常量池(高于short)
不加 final 使用常量池(高于short)
边栏推荐
- QObject::connect: Cannot queue arguments of type ‘QTextCursor‘ (Make sure ‘QTextCursor‘ is registere
- A solution to create a new EXCEL workbook on win10 computer and change the suffix to xlsm (normally it should be xlsx)
- Drill down to protobuf - Introduction
- ES6 module import / export summary
- VI editor
- ERP outlet
- Cesium achieves sunny, rainy, foggy, snowy and other effects
- Tutorial (5.0) 03 Security policy * fortiedr * Fortinet network security expert NSE 5
- Message Oriented Middleware
- Yarn package management tool
猜你喜欢
Docker installing MySQL local remote connection docker container MySQL
Invalid flex layout setting width
关于RSA加密解密原理
Use of grep
Tutorial (5.0) 02 Management * fortiedr * Fortinet network security expert NSE 5
Problems in the deconstruction and assignment of objects, comparison between empty strings and undefined
如何成为白帽子黑客?我建议你从这几个阶段开始学习
ADT Google browser plug-in ad Terminator
useRoutes() may be used only in the context of a <Router> component.
About RSA encryption and decryption principle
随机推荐
Cesium common events, including click events, mouse events, and camera movement events
关于RSA加密解密原理
Software Architecture Overview knowledge
JS obtain geographic location information according to longitude and latitude and mark it on the map
1. preliminary understanding of Express
torch. How to calculate addmm (m, mat1, mat2)
redis
Uni app subcontracting loading and optimization
The Jenkins console does not output custom shell execution logs
Installation of sonarqube code quality management platform (to be continued)
Opencv gaussianblur() explanation (Sigma value)
GBase 8a V95与V86压缩策略类比
How to resolve "the operation cannot be completed successfully because the file contains viruses or potentially junk software
JS format file unit display
20211005 Hermite矩阵及几个性质
Collection of garbled code problems in idea development environment
Problems in the deconstruction and assignment of objects, comparison between empty strings and undefined
How many TCP connections can a machine create at most?
On the use of visual studio
pytorch相同结构不同参数名模型加载权重