try-catch-finally 中,如果catch 中 return 了,finally 还会执行吗?
1public class FinallyTest {
2 public static void main(String[] args) {
3 int k = getResult();
4 System.out.println("k值:" + k);
5
6 k = getResult2();
7 System.out.println("k值:" + k);
8
9}
10
11public static int getResult() {
12 int k = 10;
13 try {
14 k = 100 / 0;
15 } catch (Exception ex) {
16 return k;
17 } finally {
18 k = 30;
19 }
20 return k;
21}
22
23public static int getResult2() {
24 int k = 10;
25 try {
26 k = 100 / 0;
27 } catch (Exception ex) {
28 return k;
29 } finally {
30 k = 30;
31 return k;
32 }
33 }
34}
在16行中
作者:洪生鹏 技术交流、媒体合作、品牌宣传请加作者微信: hsp-88ios
联系客服