public static int foo() {
int x = 0;
try {
return x;
} finally {
++x;
}
}
public static void main(String[] args) {
int res = foo();
System.out.println(res);
}
JVM会将finally中代码块内容复制到try和catch中正常return和异常throw 之前 ,这也是finally一定会执行的原因,这样不应该先执行x++,后return x吗?