finally是在return之前执行。作者: 罗威 时间: 2013-3-20 14:12
其实准确的说应该是在return中间执行的,下面是演示代码
public class Test {
public static void main(String[] args) {
System.out.println(getNumber());
}
public static int getNumber() {
int x = 10;
try {
System.out.println(10 / 0);
} catch (Exception e) {
x = 20;
return x; //return 20;
} finally {
x=30;
System.out.println("hello");
}
return 0;
}
}