当前位置:网站首页>Finally detailed explanation
Finally detailed explanation
2022-07-02 17:53:00 【Change with affection】
public class test {
public static void main(String[] args) {
System.out.println(tryTest(8));
}
public static int tryTest(int i) {
int result = 0;
Integer obj = i;
try {
System.out.println(" perform try block ");
return result;
//return obj;
} catch (Exception e) {
//return -1;
e.printStackTrace();
} finally {
// No matter whether there is any abnormality or not ||try and catch There is return,finally All the code in the block will execute
System.out.println("final Yes ");
//finally Is in return After statement execution , Return to the previous execution ( The calculated value is not returned , Instead, save the value you want to return , No matter finally
// What about the code in , The value returned will not change , It's still a previously saved value ), So the return value of the function is at finally It has been determined before implementation .
System.out.println(" Reference type variable obj: " + obj + "; Basic data type variable result: " + result);
result = i;//finally The basic data type variable in does not change the returned content
obj = null;//finally The reference to type variables in does not change the returned content
System.out.println(" Reference type variable obj: " + obj + "; Basic data type variable result: " + result);
//finally If it contains return, Then the program will return here , instead of try or catch Medium return return , The return value is not try or catch The return value saved in .
return 999;
}
}
边栏推荐
猜你喜欢
售价仅40元,树莓派Pico开发板加入WiFi模块,刚上市就脱销
finally详解
VirtualLab基础实验教程-7.偏振(1)
Viewing technological changes through Huawei Corps (VI): smart highway
Does pytorch support 32 bits?
【Golang | gRPC】使用openssl生成证书
开发一个禁止删除namespace的控制器
第十五章 字符串本地化和消息字典(一)
Pfc232-sop8/14/16 should be wide-ranging and can be tape programmed with burning program
[非线性控制理论]7_High gain and High Frequency
随机推荐
My creation anniversary
【Golang | gRPC】使用openssl生成证书
AtCoder Beginner Contest 237 VP补题
应广单片机开发调试应注意的问题
Solution pour arrêter automatiquement les paquets Jar en cours d'exécution en éteignant le serveur de connexion xshell
PMS150C应广单片机开发案例
Tips for self defined packaging of Yingguang SCM 003 burner
每日一题——小乐乐改数字
Turn off the xshell connection server and the running jar package will stop automatically
Rk1126 platform project summary
外包干了五年,废了...
[非线性控制理论]8_三种鲁棒控制器的比较
[nonlinear control theory]7_ High gain and High Frequency
维护万星开源向量数据库是什么体验
Modbus协议通信异常
Yilong em78p153k dip14 MCU
[how is the network connected] Chapter 6 requests arrive at the server and respond to the client (end)
【目标跟踪】|SiamFC
Longest non repeating subarray
What should we pay attention to in the development process of Yingguang single chip microcomputer?