当前位置:网站首页>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 !!!
边栏推荐
- Set container
- The latest tank battle 2022 full development notes-1
- [中国近代史] 第五章测验
- Leetcode. 3. Longest substring without repeated characters - more than 100% solution
- 西安电子科技大学22学年上学期《基础实验》试题及答案
- 1.初识C语言(1)
- 仿牛客技术博客项目常见问题及解答(二)
- 3.C语言用代数余子式计算行列式
- 【九阳神功】2021复旦大学应用统计真题+解析
- 20220211-CTF-MISC-006-pure_ Color (use of stegsolve tool) -007 Aesop_ Secret (AES decryption)
猜你喜欢
![[面试时]——我如何讲清楚TCP实现可靠传输的机制](/img/d6/109042b77de2f3cfbf866b24e89a45.png)
[面试时]——我如何讲清楚TCP实现可靠传输的机制

ABA问题遇到过吗,详细说以下,如何避免ABA问题

There is always one of the eight computer operations that you can't learn programming

仿牛客技术博客项目常见问题及解答(一)

3. Number guessing game

4. Binary search

Mortal immortal cultivation pointer-2

6. Function recursion

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

(超详细onenet TCP协议接入)arduino+esp8266-01s接入物联网平台,上传实时采集数据/TCP透传(以及lua脚本如何获取和编写)
随机推荐
凡人修仙学指针-1
[modern Chinese history] Chapter 9 test
ROS machine voice
C language to achieve mine sweeping game (full version)
为什么要使用Redis
Thoroughly understand LRU algorithm - explain 146 questions in detail and eliminate LRU cache in redis
Cloud native trend in 2022
用栈实现队列
FileInputStream和BufferedInputStream的比较
Wei Pai: the product is applauded, but why is the sales volume still frustrated
1.初识C语言(1)
MySQL中count(*)的实现方式
六种集合的遍历方式总结(List Set Map Queue Deque Stack)
Redis实现分布式锁原理详解
Tyut Taiyuan University of technology 2022 introduction to software engineering summary
1.C语言矩阵加减法
【九阳神功】2022复旦大学应用统计真题+解析
There is always one of the eight computer operations that you can't learn programming
MySQL锁总结(全面简洁 + 图文详解)
5.MSDN的下载和使用