public class T {
static int i=0;
public static int test() {
try {
return ++i; //先执行return
} catch (Exception e) {
} finally {
return ++i; //再执行finally里的内容,最后返回的是finally里的值
}
}
public static void main(String[] args) {
System.out.println(test());
}
}
输出2
public class T {
static int i=0;
public static int test() {
try {
return ++i; //先执行return
} catch (Exception e) {
} finally {
return ++i; //再执行finally里的内容,最后返回的是finally里的值
}
}
public static void main(String[] args) {
System.out.println(test());
}
}
输出2