public class FinallyTest {
public static void main(String[] args) {
System.out.println(new FinallyTest().test());//这个打印结果为1.
System.out.println(new FinallyTest().get());// 这个打印结果为2.
}
//调这个就打印1
static int test() {
int x = 1;
try {
return x;
} finally {
++x;
}
}
//调这个就打印2
static public int get() {
try {
return 1;
} finally {
return 2;
}
}
}