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

边栏推荐
- 应广单片机开发 工规 PMC131 带AD芯片检测电池电压单片机SOP8/14
- Making tutorial of chicken feet with pickled peppers
- PMS132B单片机TWS数码管蓝牙充电仓方案开发
- No such file or directory: ‘/tmp/tmpxxx/tmpxxx.py‘
- ROS knowledge point - message_filters
- uva1169
- Are you holding back on the publicity of the salary system for it posts such as testing, development, operation and maintenance?
- Wechat applet - arrows floating up and down
- USB interface powered Bluetooth color light strip controller
- vector的底层模拟实现
猜你喜欢

阿里天池SQL学习笔记——DAY3

After meeting a full stack developer from Tencent, I saw what it means to be proficient in MySQL tuning

freemarker+poi实现动态生成excel文件及解析excel文件

Modbus协议通信异常

Modbus协议通信异常

This "architect growth note" made 300 people successfully change jobs and enter the big factory, with an annual salary of 50W
![[today in history] July 2: BitTorrent came out; The commercial system linspire was acquired; Sony deploys Playstation now](/img/16/574eee53720fd609027950b9bf8154.png)
[today in history] July 2: BitTorrent came out; The commercial system linspire was acquired; Sony deploys Playstation now

The bottom simulation implementation of vector

Si446 usage record (II): generate header files using wds3

一日2篇Nature!中科大校友段镶锋团队纳米材料新成果,曾是贝尔比奖章第三位华人得主...
随机推荐
第十五章 字符串本地化和消息字典(一)
[target tracking] |siamfc
[how is the network connected] Chapter 6 requests arrive at the server and respond to the client (end)
uva1169
【GAMES101】作业4 Bézier 曲线
Daily question - inverted string
OpenHarmony如何启动FA(本地和远程)
Huimang micro IO MCU ft60f010a-urt
Asemi rectifier bridge umb10f parameters, umb10f specifications, umb10f package
JDBC
辉芒微IO单片机FT60F011A-RB
SAP Commerce Cloud 架构概述
Huimang micro IO MCU ft60f011a-rb
什么是软件开发中的 green field 和 brown field 模式 - 绿地开发和棕地开发
维护万星开源向量数据库是什么体验
Mb10m-asemi rectifier bridge mb10m
Si446 usage record (I): basic data acquisition
应广PMC131 SOP16 16pin八位单片机
CEPH principle
MATLAB中nexttile函数使用