当前位置:网站首页>Differences among fianl, finally, and finalize
Differences among fianl, finally, and finalize
2022-07-06 13:39:00 【Wake up duck, did you program today?】
First of all, there is no essential relationship between the three , During the interview, we will check our understanding of this :
fianl
fianl Is used to modify variables , decorator , Modifier class attribute , When it modifies variables , The reference of the variable is immutable, but the content of the address can be changed , When it modifies a class , This class cannot be inherited but can be overloaded , When it modifies class attributes , Subclasses cannot reassign this property , If the value is assigned, an error will be reported .
finally
Common words try catch finally in , Used in exception handling finally Perform any cleanup , Whether or not there are exceptions thrown and caught finally All statements in will execute
If try There are... In the code block return sentence ,return The statement must be executed last ,java There is an eternal rule in , The program is executed line by line from top to bottom , Once implemented return The whole method ends .
Let's look at a topic :
package com.ws;
public class Demo02 {
public static void main(String[] args) {
int result = m();
System.out.println(result);
}
public static int m(){
int i = 100;
try{
return i;
}finally {
i++;
}
}
}
What are the above output results ? I guess most people will say yes 101, But the answer is 100

Let's take a look at the decompiled code
// The following is the decompiled code
public static int m(){
int i = 100;
int j = i;
i++;
return j;
Exception exception;
exception;
i++;
throw exception;
}The first is to put i The value of j, then i++( Is to perform fianlly Code inside ), Then return j.
finalize
In garbage collection , If the recycled object overrides finalize() Method , And in finalize() Method to re-establish the object and GC ROOT The connection of , Then the object can be resurrected once , That is, the object will return to the application stage from the collection stage .
The above is the difference between the three !!!
边栏推荐
- [hand tearing code] single case mode and producer / consumer mode
- 六种集合的遍历方式总结(List Set Map Queue Deque Stack)
- 西安电子科技大学22学年上学期《射频电路基础》试题及答案
- Application architecture of large live broadcast platform
- [面试时]——我如何讲清楚TCP实现可靠传输的机制
- 稻 城 亚 丁
- 6.函数的递归
- 【九阳神功】2020复旦大学应用统计真题+解析
- Leetcode.3 无重复字符的最长子串——超过100%的解法
- Custom RPC project - frequently asked questions and explanations (Registration Center)
猜你喜欢
随机推荐
5月14日杂谈
Detailed explanation of redis' distributed lock principle
MySQL limit x, -1 doesn't work, -1 does not work, and an error is reported
View UI plus released version 1.3.0, adding space and $imagepreview components
Arduino+ water level sensor +led display + buzzer alarm
Voir ui plus version 1.3.1 pour améliorer l'expérience Typescript
Floating point comparison, CMP, tabulation ideas
(原创)制作一个采用 LCD1602 显示的电子钟,在 LCD 上显示当前的时间。显示格式为“时时:分分:秒秒”。设有 4 个功能键k1~k4,功能如下:(1)k1——进入时间修改。
View UI Plus 发布 1.1.0 版本,支持 SSR、支持 Nuxt、增加 TS 声明文件
arduino+水位传感器+led显示+蜂鸣器报警
5.MSDN的下载和使用
编写程序,模拟现实生活中的交通信号灯。
Redis cache obsolescence strategy
View UI plus released version 1.3.1 to enhance the experience of typescript
[中国近代史] 第五章测验
MySQL Database Constraints
7. Relationship between array, pointer and array
凡人修仙学指针-2
1.C语言初阶练习题(1)
IPv6 experiment




![[hand tearing code] single case mode and producer / consumer mode](/img/b3/243843baaf0d16edeab09142b4ac09.png)



