当前位置:网站首页>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;
}
}

边栏推荐
- How openharmony starts fa (local and remote)
- uva1169
- VirtualLab基础实验教程-7.偏振(1)
- [非线性控制理论]7_High gain and High Frequency
- Si446 usage record (II): generate header files using wds3
- Si446 usage record (I): basic data acquisition
- Huimang micro IO MCU ft60f011a-rb
- ROS knowledge points -- the difference between ros:: nodehandle N and NH ("~")
- 【目标跟踪】|SiamFC
- PCL knowledge points - voxelized grid method for down sampling of point clouds
猜你喜欢

Microservice architecture practice: Construction of scalable distributed database cluster

Ssm+ wechat applet to realize property management system

【目标跟踪】|数据集汇总

我的创作纪念日

Income and risk of linear programming example investment

VirtualLab基础实验教程-7.偏振(2)

【网络是怎么连接的】第四章 探索接入网和网络运营商

【網絡是怎樣連接的】第六章 請求到達服務器以及響應給客戶端(完結)

Easyswoole3.2 restart failed

科班出身,面试小公司都进不去
随机推荐
【目标跟踪】|数据集汇总
Income and risk of linear programming example investment
蓝牙技术|物联网的可穿戴设备新工作模式,蓝牙BLE助力新工作模式
每日一题——倒置字符串
维护万星开源向量数据库是什么体验
How to create a new page for SAP Spartacus storefront
wps插入图片后使图片完整显示
Map集合详细讲解
uva1169
把xshell连接服务器关掉,运行的jar包就自动停止的解决方案
When the industrial Internet began to enter the deep-water area, it appeared more in the form of industry
Are you holding back on the publicity of the salary system for it posts such as testing, development, operation and maintenance?
原厂原装 应广单片机PMS134方案开发应用案例
Asemi rectifier bridge umb10f parameters, umb10f specifications, umb10f package
Keras深度学习实战——基于VGG19模型实现性别分类
Vscode knowledge points - Common Errors
RK1126平台项目总结
Solving simple differential equations
第十五章 字符串本地化和消息字典(一)
Larvel document reading notes custom authentication login and registration using larvel 8