当前位置:网站首页>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 .
边栏推荐
- Leetcode 1962. Remove stones to minimize the total amount (should be rounded up)
- Leetcode 1968. Construct an array whose elements are not equal to the average value of two adjacent elements (yes, finally solved)
- 无延时/无延迟视频直播实例效果案例
- How to quickly compress the size of video?
- 基于Qt开发实现的任务管理器
- C language learning record 6
- Recommended open source scheduling libraries worth learning
- Vi LXD deployment of lab server for development records
- 折叠表达式
- Extracting storage is the best memory method
猜你喜欢

airtest自动化测试

Vi LXD deployment of lab server for development records

Two small things, feel the gap with the great God
![[public class preview]: mxplayer Ott audio and video transcoding practice and optimization](/img/d8/a367c26b51d9dbaf53bf4fe2a13917.png)
[public class preview]: mxplayer Ott audio and video transcoding practice and optimization

二十八-三维点云实时和离线生成二维栅格、三维栅格地图

【公开课预告】:MXPlayer OTT音视频转码实践和优化

使用cpolar远程办公(1)

IC fresh Chinese cabbage price of 400000 yuan! Experienced experts who have worked for many years guide you how to choose an offer!

Xiaomi 9-wire brush ROM

为什么每运行一部都显示一次数据库已存在,都要删除数据库,然后才能成功,每运行一部都要删除一次数据库,重新运行整体才成功.
随机推荐
cadence SPB17.4 - group operation(add to group, view group list, delete group)
Terrain + ansible implements infrastructure and configuration management
couldn‘t upgrade db schema: insert into ACT_ GE_ Property values ('common.sche[resolved]
Is the securities account opened in qiniu safe? How to apply for a low commission stock account?
【Try to Hack】URL
Explanation of waitgroup usage in go language learning
提取式存储才是最佳的记忆方法
Three level classification display
Stochastic dynamic economic dispatching model of wind power (realized by matlab code)
Implementation of VGA protocol based on FPGA
Question bank and answers of the latest national fire-fighting facility operators (primary fire-fighting facility operators) in 2022
论文导读 | 机器学习在数据库基数估计中的应用
Distributed file system and enterprise application -- elk enterprise log analysis system
[signal de-noising] chromatographic baseline estimation and de-noising based on sparsity (beads) with matlab code and papers
Installation and use of Anaconda
Check box select all or deselect all
Question bank and answers for 2022 tool fitter (intermediate) operation certificate examination
[signal processing] digital signal processing matlab design with GUI interface and report
couldn‘t upgrade db schema: insert into ACT_GE_PROPERTY values (‘common.sche[已解决]
C# 设置窗体和系统的光标形状