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

边栏推荐
- PMS132B单片机TWS数码管蓝牙充电仓方案开发
- wps插入图片后使图片完整显示
- uva1169
- After meeting a full stack developer from Tencent, I saw what it means to be proficient in MySQL tuning
- 【网络是怎么连接的】第四章 探索接入网和网络运营商
- Use of nexttile function in MATLAB
- 应广单片机(MCU单片机科普)
- Huimang micro IO MCU ft60f11f-mrb
- JDBC
- Si446 usage record (II): generate header files using wds3
猜你喜欢

Larvel document reading notes custom authentication login and registration using larvel 8

PFC232-SOP8/14/16应广一级可带烧录程序编带

Chrome browser quick access stackoverflow

USB interface powered Bluetooth color light strip controller

阿里云子账户 - 权限策略 - 授权给某个账户某个 OSS Bucket 的完全控制权限

ASEMI整流桥UMB10F参数,UMB10F规格,UMB10F封装

Edgenext hit a mixed punch: a lightweight architecture integrating CNN and transformer

【Zuul】com.netflix.zuul.exception.ZuulException: Hystrix Readed time out

Solution to the problem that the easycvr kernel of intelligent video analysis platform cannot be started as a service
![[target tracking] |siamfc](/img/40/3419761d2eb7f1193b699cdd431761.png)
[target tracking] |siamfc
随机推荐
应广单片机PMS150/PMC150/PMS150C消费类单片机
如何给 SAP Spartacus Storefront 创建新的页面
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
台湾飞凌FM8PB513B单片机提供单片机方案开发 产品设计
SAP commerce Cloud Architecture Overview
2 juillet: BitTorrent est sorti; L'acquisition du système commercial linspire; Sony Deployment PlayStation now
The construction of scalable distributed database cluster and the partition design of oneproxy sub database
HDU - 1114 Piggy Bank (full backpack)
Niuke js3 separator
easyAI笔记——机器学习
链表求和[dummy+尾插法+函数处理链表引用常见坑位]
微信小程序 —— 上下浮动的箭头
easyAI笔记——深度学习
台风来袭,多景区暂时关闭,省文旅厅提醒注意安全!
将您的基于 Accelerator 的 SAP Commerce Cloud Storefront 迁移到 Spartacus
Si446 usage record (I): basic data acquisition
Ssm+ wechat applet to realize property management system
【网络是怎么连接的】第四章 探索接入网和网络运营商
科班出身,面试小公司都进不去