当前位置:网站首页>finally详解
finally详解
2022-07-02 15:56:00 【深情以改】
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("执行try块");
return result;
//return obj;
} catch (Exception e) {
//return -1;
e.printStackTrace();
} finally {
//不管有没有异常||try和catch中有return,finally块中代码都会执行
System.out.println("final执行了");
//finally是在return语句执行之后,返回之前执行的(此时并没有返回运算后的值,而是先把要返回的值保存起来,不管finally
// 中的代码怎么样,返回的值都不会改变,仍然是之前保存的值),所以函数返回值是在finally执行前就已经确定了。
System.out.println("引用类型变量obj: " + obj + "; 基本数据类型变量result: " + result);
result = i;//finally中基本数据类型变量并不会改变返回的内容
obj = null;//finally中引用类型变量也不会改变返回的内容
System.out.println("引用类型变量obj: " + obj + "; 基本数据类型变量result: " + result);
//finally中如果包含return,那么程序将在这里返回,而不是try或catch中的return返回,返回值就不是try或catch中保存的返回值了。
return 999;
}
}

边栏推荐
- Daily question - "number of daffodils"
- MATLAB中nexttile函数使用
- What is the experience of maintaining Wanxing open source vector database
- Séparateur JS3 de niuke
- 【历史上的今天】7 月 2 日:BitTorrent 问世;商业系统 Linspire 被收购;索尼部署 PlayStation Now
- SAP commerce Cloud Architecture Overview
- 2 juillet: BitTorrent est sorti; L'acquisition du système commercial linspire; Sony Deployment PlayStation now
- Map集合详细讲解
- Huimang micro IO MCU ft60f010a-urt
- 智能水电表能耗监测云平台
猜你喜欢
随机推荐
The bottom simulation implementation of vector
Atcoder beginer contest 237 VP supplement
Mb10m-asemi rectifier bridge mb10m
蓝牙技术|物联网的可穿戴设备新工作模式,蓝牙BLE助力新工作模式
[target tracking] |siamfc
Huimang micro IO MCU ft60f11f-mrb
freemarker+poi实现动态生成excel文件及解析excel文件
VirtualLab基础实验教程-7.偏振(2)
牛客 JS3 分隔符
Uniapp H5 page calls wechat payment
微信小程序 —— 上下浮动的箭头
应广单片机开发调试应注意的问题
阿里云子账户 - 权限策略 - 授权给某个账户某个 OSS Bucket 的完全控制权限
【网络是怎么连接的】第四章 探索接入网和网络运营商
Are you holding back on the publicity of the salary system for it posts such as testing, development, operation and maintenance?
Navigateur Chrome pour un accès rapide au stackoverflow
After meeting a full stack developer from Tencent, I saw what it means to be proficient in MySQL tuning
[how is the network connected] Chapter 6 requests arrive at the server and respond to the client (end)
Daily question - xiaolele changes the number
Easyswoole3.2 restart failed









