public class FinallyTest {
public static void main(String[] args) {
int a = 0;
try {
a = 3;
int k = testfinall(a);
System.out.println("return value k="+k);
} catch (Exception e) {
System.out.println(a);
} finally {
System.out.println(a);
}
}
//值传递
public static int testfinall(int a) {
try {
a = 8;
return returnBeforFinnaly(a);//先将当前计算的结果保留。以便返回是用
} finally {
System.out.println("finally....."+a);
//return a; 如果这里还有一个 return 实际返回值以这个return 为主
}
}
//值传递
public static int returnBeforFinnaly(int a){
System.out.println("returnBeforFinnaly...a="+a);
return a++;
}
}