当前位置:网站首页>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;
}
}
边栏推荐
- pytorch支持32位吗?
- From collection to output: inventory those powerful knowledge management tools - inventory of excellent note taking software (4)
- VirtualLab基础实验教程-7.偏振(1)
- 微信小程序 —— 上下浮动的箭头
- Modbus protocol communication exception
- 辉芒微IO单片机FT60F011A-RB
- Microservice architecture practice: using Jenkins to realize automatic construction
- win10 kms activator
- 【網絡是怎樣連接的】第六章 請求到達服務器以及響應給客戶端(完結)
- Wasserstein Slim GAIN with Clipping Penalty(WSGAIN-CP)介绍及代码实现——基于生成对抗网络的缺失数据填补
猜你喜欢
每日一题——倒置字符串
Use of nexttile function in MATLAB
wps插入图片后使图片完整显示
[how to connect the network] Chapter 5 explore the server
Microservice architecture practice: Construction of highly available distributed file system fastdfs architecture
Larvel document reading notes custom authentication login and registration using larvel 8
【网络是怎样连接的】第五章 探索服务器
Alibaba Tianchi SQL learning notes - Day3
Example nonlinear integer programming
MATLAB中nexttile函数使用
随机推荐
[today in history] July 2: BitTorrent came out; The commercial system linspire was acquired; Sony deploys Playstation now
应广PMC131 SOP16 16pin八位单片机
Chapter 15 string localization and message Dictionary (1)
Niuke js3 separator
Huimang micro IO MCU ft60f010a-urt
Alibaba cloud sub account - Permission Policy - full control permission granted to an account and an OSS bucket
外包干了五年,废了...
【网络是怎样连接的】第六章 请求到达服务器以及响应给客户端(完结)
将您的基于 Accelerator 的 SAP Commerce Cloud Storefront 迁移到 Spartacus
阿里天池SQL学习笔记——DAY3
Modbus协议通信异常
VirtualLab基础实验教程-7.偏振(1)
Platform management background and merchant menu resource management: merchant role management design
原厂原装 应广单片机PMS134方案开发应用案例
Solution pour arrêter automatiquement les paquets Jar en cours d'exécution en éteignant le serveur de connexion xshell
智能水电表能耗监测云平台
Huimang micro IO MCU ft60f11f-mrb
JS20 数组扁平化
原装应广单片机 MCU芯片PMS152 SOP8封装 单片机开发
What are the green field and brown field models in software development - green field development and brown field development