首页 > 其他 > 详细

try-catch-finally 中的return 语句

时间:2019-07-29 16:52:55      阅读:70      评论:0      收藏:0      [点我收藏+]

如果finally块中有return语句的话,它将覆盖掉函数中其他return语句。

public class Demo{
 public static void main(String args[]){
   int num = 10;
   System.out.println(test(num));
}
public static int test(int b){
   try
   {
    b += 10;
    return b;
   }
   catch(RuntimeException e)
   {
   }
   catch(Exception e2)
   {
   }
   finally
   {
    b += 10;
    return b;
   }
  }
}
 
返回30

try-catch-finally 中的return 语句

原文:https://www.cnblogs.com/67373cyf/p/11264492.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!