当前位置:网站首页>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 !!!
边栏推荐
- String abc = new String(“abc“),到底创建了几个对象
- 5月14日杂谈
- 透彻理解LRU算法——详解力扣146题及Redis中LRU缓存淘汰
- [hand tearing code] single case mode and producer / consumer mode
- 使用Spacedesk实现局域网内任意设备作为电脑拓展屏
- 5.函数递归练习
- Questions and answers of "signal and system" in the first semester of the 22nd academic year of Xi'an University of Electronic Science and technology
- 4.二分查找
- arduino+DS18B20温度传感器(蜂鸣器报警)+LCD1602显示(IIC驱动)
- Mortal immortal cultivation pointer-1
猜你喜欢
View UI Plus 发布 1.2.0 版本,新增 Image、Skeleton、Typography组件
Leetcode.3 无重复字符的最长子串——超过100%的解法
Questions and answers of "signal and system" in the first semester of the 22nd academic year of Xi'an University of Electronic Science and technology
Pit avoidance Guide: Thirteen characteristics of garbage NFT project
自定义RPC项目——常见问题及详解(注册中心)
3. C language uses algebraic cofactor to calculate determinant
[au cours de l'entrevue] - Comment expliquer le mécanisme de transmission fiable de TCP
仿牛客技术博客项目常见问题及解答(一)
Wei Pai: the product is applauded, but why is the sales volume still frustrated
C language Getting Started Guide
随机推荐
【九阳神功】2017复旦大学应用统计真题+解析
Redis的两种持久化机制RDB和AOF的原理和优缺点
杂谈0516
Rich Shenzhen people and renting Shenzhen people
FileInputStream和BufferedInputStream的比较
【九阳神功】2016复旦大学应用统计真题+解析
Mortal immortal cultivation pointer-2
Service ability of Hongmeng harmonyos learning notes to realize cross end communication
2. Preliminary exercises of C language (2)
Pit avoidance Guide: Thirteen characteristics of garbage NFT project
3.猜数字游戏
arduino+DS18B20温度传感器(蜂鸣器报警)+LCD1602显示(IIC驱动)
MySQL limit x, -1 doesn't work, -1 does not work, and an error is reported
【九阳神功】2022复旦大学应用统计真题+解析
[during the interview] - how can I explain the mechanism of TCP to achieve reliable transmission
View UI Plus 發布 1.3.1 版本,增强 TypeScript 使用體驗
【九阳神功】2019复旦大学应用统计真题+解析
编写程序,模拟现实生活中的交通信号灯。
fianl、finally、finalize三者的区别
2.C语言初阶练习题(2)