当前位置:网站首页>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 !!!
边栏推荐
- [the Nine Yang Manual] 2017 Fudan University Applied Statistics real problem + analysis
- 最新坦克大战2022-全程开发笔记-3
- 1. C language matrix addition and subtraction method
- View UI Plus 发布 1.1.0 版本,支持 SSR、支持 Nuxt、增加 TS 声明文件
- 5. Download and use of MSDN
- MPLS experiment
- Share a website to improve your Aesthetics
- 杂谈0516
- [the Nine Yang Manual] 2021 Fudan University Applied Statistics real problem + analysis
- [the Nine Yang Manual] 2020 Fudan University Applied Statistics real problem + analysis
猜你喜欢
There is always one of the eight computer operations that you can't learn programming
MySQL Database Constraints
(ultra detailed onenet TCP protocol access) arduino+esp8266-01s access to the Internet of things platform, upload real-time data collection /tcp transparent transmission (and how to obtain and write L
C语言实现扫雷游戏(完整版)
C语言入门指南
Cloud native trend in 2022
Mortal immortal cultivation pointer-2
Smart classroom solution and mobile teaching concept description
仿牛客技术博客项目常见问题及解答(三)
MySQL lock summary (comprehensive and concise + graphic explanation)
随机推荐
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
[面试时]——我如何讲清楚TCP实现可靠传输的机制
ABA问题遇到过吗,详细说以下,如何避免ABA问题
(super detailed II) detailed visualization of onenet data, how to plot with intercepted data flow
4.分支语句和循环语句
Redis的两种持久化机制RDB和AOF的原理和优缺点
Change vs theme and set background picture
甲、乙机之间采用方式 1 双向串行通信,具体要求如下: (1)甲机的 k1 按键可通过串行口控制乙机的 LEDI 点亮、LED2 灭,甲机的 k2 按键控制 乙机的 LED1
仿牛客技术博客项目常见问题及解答(一)
Cloud native trend in 2022
[modern Chinese history] Chapter V test
【九阳神功】2021复旦大学应用统计真题+解析
1.C语言矩阵加减法
Redis cache obsolescence strategy
Network layer 7 protocol
CorelDRAW plug-in -- GMS plug-in development -- Introduction to VBA -- GMS plug-in installation -- Security -- macro Manager -- CDR plug-in (I)
【九阳神功】2022复旦大学应用统计真题+解析
Share a website to improve your Aesthetics
[the Nine Yang Manual] 2021 Fudan University Applied Statistics real problem + analysis
IPv6 experiment