当前位置:网站首页>I have something to say about final, finally and finalize
I have something to say about final, finally and finalize
2022-06-11 14:08:00 【sniper_ fandc】
final
final Keywords are used to decorate classes 、 Method 、 Variable .
1. When a class is decorated, it means that the class cannot be inherited , It is mainly used to consider the security of classes . Attention should be paid to , One final Member methods of a class are implicitly defined as final Method .
2. When decorating a method, the representation cannot be overridden , Subclasses can inherit , But you can't rewrite it .
3. When you modify a variable, it means that the variable is a constant , That is, it can only be explicitly assigned once during initialization , Cannot be reassigned .
finally
be chiefly used in try-catch The last resource release in exception capture , Some people here think finally The statement must be executed to , Let's look at the following code :
//1.try-catch Abnormal exit
try {
System.exit(1)
} catch {
....
} finally {
// It's not going to work here
Log.d("finally", "finally");
}
//2. Infinite loop
try {
while(true) {
...
}
} finally {
// It's not going to work here
Log.d("finally", "finally");
}
//3. Thread killed
// When executed try-catch when , The thread was killed , that finally The code in can't be executed to
finalize
This method is included in Object class , It is mainly called when the object is recycled , Do some resource release work . But use finalize Attention is also needed , call super.finalize(), Of an object finalize() Methods are called only once , and finalize() Being called does not mean that the object will be reclaimed immediately , So it's possible to call finalize() after , The object doesn't need to be recycled again , And then it's time to actually recycle , Because I called it once before , So it won't call finalize(), A problem . therefore , It is not recommended to use finalize() Method .
边栏推荐
- Stochastic dynamic economic dispatching model of wind power (realized by matlab code)
- .NET C#基础(6):命名空间 - 有名字的作用域
- Check box select all or deselect all
- [signal processing] digital signal processing matlab design with GUI interface and report
- Single table query of SQL data query
- No delay / no delay live video instance effect cases
- Code comparison tool, I use these six
- Optimal dispatching (thermal power, wind and energy storage) (realized by Matlab)
- 2022工具钳工(中级)操作证考试题库及答案
- Zhu Ping: in the post epidemic era, medical beauty operations should not only be distracted, but also reverse the routine
猜你喜欢

YOLOv3学习笔记:YOLOv3的模型结构

阿里一面,谈谈策略模式在项目中的使用

六.开发记录之实验室服务器LXD部署

Zhu Ping: in the post epidemic era, medical beauty operations should not only be distracted, but also reverse the routine

Learning notes of yolov3: model structure of yolov3

Leetcode 1968. Construct an array whose elements are not equal to the average value of two adjacent elements (yes, finally solved)

.NET C#基础(6):命名空间 - 有名字的作用域

【Flink】Flink CancellationException null DefaultExecutionGraphCache LeaderRetrievalHandler

折叠表达式

Collapse expression
随机推荐
C # set the cursor shape of forms and systems
Leetcode 1962. Remove stones to minimize the total amount (should be rounded up)
tampermonkey这玩意如何替换flash播放器为h5播放器?
提取式存储才是最佳的记忆方法
Customize terrain providers (terrain plugin framework) -04
Unsealing easy QF PDA helps enterprises improve ERP management
Xiaomi 9-wire brush ROM
Easyexcel configuration and Application
Bs-xx-007 registered residence management system based on JSP
C. Mortal Kombat Tower(cf)dp
.NET C#基础(6):命名空间 - 有名字的作用域
The application of machine learning in database cardinality estimation
VIM secondary replacement
How to quickly compress the size of video?
JSTL custom label
Leetcode 1968. Construct an array whose elements are not equal to the average value of two adjacent elements (yes, finally solved)
Work summary: it took a long time to write SQL because of Cartesian product problem (Cartesian product summary attached)
Ponds(拓扑 + 优先队列)
二十八-三维点云实时和离线生成二维栅格、三维栅格地图
Question bank and answers for 2022 tool fitter (intermediate) operation certificate examination