try-catch-finally 中的return 语句

如果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
posted @ 2019-07-29 16:12  海贼王说他今天很开心  阅读(146)  评论(0编辑  收藏  举报