当前位置:网站首页>Return and finally? Everyone, please look over here,
Return and finally? Everyone, please look over here,
2022-07-25 11:52:00 【Whew, fly over】
Thinking questions 1 :
return and finally Execution order of ?
answer : return Execute first Stop the method , After execution finally , Last In execution return Return the value to
for example :
public class Return_Finally {
public static void main(String[] args) {
System.out.println(A.a());
}
}
class A {
public static int a() {
int i = 1;
try{
return i;
}finally {
System.out.println("f1==>>"+i);
++i;
System.out.println("f2==>>"+i);
}
}
}
result :
You can see it in finally It has changed in the past i The value of finally returns 1, This is the second question to be discussed :
Thinking questions 2 :
finally perform , then return Return the value to , If in finally Changed the value , that retrun Will the value after change ?
answer : Sub situation : retrun The data type of the returned value
Basic data type
return Returns the basic data type , And finally There is no return, Just change the value of the variable , This situation
finally It does not affect the final return Value
Reference data type
return Return the reference data type ( except String), And finally There is no return, Just change the value of the reference type , This situation
finally Will affect the final return Value
If finally There is retrun Words , So finally in return The returned value shall prevail !
边栏推荐
猜你喜欢

W5500在处于TCP_Server模式下,在交换机/路由器网络中无法ping通也无法通讯。

Summary of combination problems of Li Kou brush questions (backtracking)

Wiznet embedded Ethernet technology training open class (free!!!)

brpc源码解析(八)—— 基础类EventDispatcher详解

OneNET平台控制W5500开发板LED灯

阿里云技术专家秦隆:可靠性保障必备——云上如何进行混沌工程

基于W5500实现的考勤系统

Maskgae: masked graph modeling meets graph autoencoders

WIZnet嵌入式以太网技术培训公开课(免费!!!)

Javescript loop
随机推荐
【mysql学习08】
任何时间,任何地点,超级侦探,认真办案!
阿里云技术专家秦隆:可靠性保障必备——云上如何进行混沌工程
Brpc source code analysis (VIII) -- detailed explanation of the basic class eventdispatcher
JS process control
Make a reliable delay queue with redis
SQL injection less23 (filter comment)
【电子器件笔记5】二极管参数和选型
Activity registration | play with kubernetes container service improvement class officially opened!
动态规划问题03_最大子段和
DICOM medical image viewing and browsing function based on cornerstone.js
JS数据类型以及相互转换
SQL language (4)
brpc源码解析(二)—— brpc收到请求的处理过程
教你如何通过MCU将S2E配置为UDP的工作模式
How to judge the performance of static code quality analysis tools? These five factors must be considered
绘图==PYQT5
MIIdock简述
教你如何通过MCU配置S2E为TCP Client的工作模式
[imx6ull notes] - a preliminary exploration of the underlying driver of the kernel
