public class TestTry {
public static void main(String[] args) {
System.out.println("a in main:"+a());
}
static int a(){
int a=1;
try{
a++;
System.out.println("a in try:"+a);
return ++a;
}finally{
a++;
System.out.println("a in finally:"+a);
}
}
}
结果:a in try:2
a in finally:4
a in main:3
结论:先执行return语句,后执行finally里的语句,最后返回return语句的值。