当前位置:网站首页>3. What is the difference between final, finally, and finalize?
3. What is the difference between final, finally, and finalize?
2022-08-03 06:22:00 【Shiyu】
One, final immutable
Usually used to modify a class or a method or a variable
1. When modifying a class, it means that this class cannot be inherited.(Avoid overriding methods, change some functions)
2. When modifying a method, it means that this method cannot be overridden.(same as above)
3. When modifying a variable, it means that the reference to this variable cannot be changed.(Ensure that the value of the variable is correct and avoid being modified randomly)
Second, finally the last
It is usually used with try-catch block to ensure that the last one is processed after some business is processed, such as closing the database connection and waiting.Normally it will be implemented.
Note: It may not be executed. For example, an infinite loop while(true) is used in try or the program System.exit(1), System.exit(0) is exited in advance.
System.exit(0): exit normally
System.exit(1): Abnormal exit
Three, finalize completed
A method of java.lang.obejct, which is used to reclaim some specific resources before the object is reclaimed by the garbage processor.
边栏推荐
猜你喜欢
随机推荐
ZEMAX | 如何创建简单的非序列系统
A.1#【内存管理】——1.1.3 page: struct page
ue4学习日记4(植被,光照,光束遮挡,天空球)
2-php学习笔记之控制语句,函数
ZEMAX | 如何使用渐晕系数
树——前序
移动端人脸风格化技术的应用
电容器和电池有什么不同?
Practice of MySql's Sql statement (try how many you can write)
ZEMAX | 如何创建复杂的非序列物体
【C语言】关于数组传参问题/首地址
POE交换机全方位解读(中)
servlet学习(七)ServletContext
ZEMAX | 绘图分辨率结果对光线追迹的影响
自监督论文阅读笔记 Ship Detection in Sentinel 2 Multi-Spectral Images with Self-Supervised Learning
MATLAB自带的dwt2和wavedec2函数实现基于小波变换的自适应阈值图像边缘检测
SolidWorks 操作视频 | 流体分析结果演示
MySql【后面附有练习题】
ucosII OSMemCreate()函数的解析
常见的电子元器件分类介绍









