public static int test(){
int i = 0;
try {
i++;
throw new Exception("eeee");
} catch( Exception e) {
return i;
} finally {
i++;
}
}
public static String test2(){
String test = "111";
try {
test = "222";
throw new Exception("eeeee");
} catch( Exception e) {
return test;
} finally {
test = "333";
}
}
public StringBuffer test3(){
StringBuffer test = new StringBuffer();
try {
test.append("123");
throw new Exception("Test");
} catch( Exception e) {
return test;
} finally {
test.append("456");
}
}
其实这个问题,可以这样解释:
return的时候相当于赋值给一个中间变量,然后再return。例如,第一个test()中的return i,相当于int b=i;return b;