作者: 淡夜清风 时间: 2014-1-11 16:54
看了楼主的解释感觉是对的。。
源程序输出结果:
before return8
before finally8
after finally9
8
----------------------
如果代码改成:
public class FinallyTest {
public static void main(String[] args) {
System.out.println(FinallyTest.test());
}
static int test() {
int x = 8;
try {
System.out.println("before return" + x);
return x;
} finally {
System.out.println("before finally" + x);
++x;
if(x>8)
return x;
System.out.println("after finally" + x);
}
}
}
输出结果:
before return8
before finally8
9