当前位置:网站首页>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 !!!
边栏推荐
- 4.二分查找
- [the Nine Yang Manual] 2022 Fudan University Applied Statistics real problem + analysis
- hashCode()与equals()之间的关系
- Change vs theme and set background picture
- View UI Plus 发布 1.1.0 版本,支持 SSR、支持 Nuxt、增加 TS 声明文件
- Set container
- 4.分支语句和循环语句
- JS interview questions (I)
- fianl、finally、finalize三者的区别
- [the Nine Yang Manual] 2021 Fudan University Applied Statistics real problem + analysis
猜你喜欢

(超详细onenet TCP协议接入)arduino+esp8266-01s接入物联网平台,上传实时采集数据/TCP透传(以及lua脚本如何获取和编写)

1.C语言矩阵加减法

View UI Plus 发布 1.3.0 版本,新增 Space、$ImagePreview 组件

MySQL lock summary (comprehensive and concise + graphic explanation)

Mortal immortal cultivation pointer-2

Cookie和Session的区别

arduino+水位传感器+led显示+蜂鸣器报警

甲、乙机之间采用方式 1 双向串行通信,具体要求如下: (1)甲机的 k1 按键可通过串行口控制乙机的 LEDI 点亮、LED2 灭,甲机的 k2 按键控制 乙机的 LED1

FAQs and answers to the imitation Niuke technology blog project (III)

Wei Pai: the product is applauded, but why is the sales volume still frustrated
随机推荐
凡人修仙学指针-2
View UI Plus 发布 1.1.0 版本,支持 SSR、支持 Nuxt、增加 TS 声明文件
5月27日杂谈
View UI plus released version 1.3.0, adding space and $imagepreview components
自定义RPC项目——常见问题及详解(注册中心)
学编程的八大电脑操作,总有一款你不会
抽象类和接口的区别
3. Number guessing game
FAQs and answers to the imitation Niuke technology blog project (III)
5月14日杂谈
【毕业季·进击的技术er】再见了,我的学生时代
这次,彻底搞清楚MySQL索引
Write a program to simulate the traffic lights in real life.
hashCode()与equals()之间的关系
2.初识C语言(2)
3.输入和输出函数(printf、scanf、getchar和putchar)
【九阳神功】2017复旦大学应用统计真题+解析
fianl、finally、finalize三者的区别
最新坦克大战2022-全程开发笔记-3
Detailed explanation of redis' distributed lock principle