您的位置:首页 > 其它

try catch finally 有return的执行顺序

2017-02-19 11:13 441 查看
try catch 中有return的时候,finally 的代码一定会执行

测试代码:

public class FinallyReturnDemo {

public static void main(String[] args) {
try{
System.out.println(1);
return ;

}catch(Exception e){
System.out.println(2);
}finally {
System.out.println(3);
}
System.out.println(4);
}

}
运行代码:

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: