大家都知道finally语句块是在return语句之前完成的,那么谁能解释一下下面的现象呢?请看代码:
public class FinallyReturnDemo
{
public static void main(String[] args)
{
System.out.println("main: "+test());
}
private static int test(){
int x = 1;
try{
System.out.println("try: x = "+x);
return x;
}catch(Exception e){
throw new RuntimeException(e);
}finally{
++x;
System.out.println("finally: x = "+x);
}
}
}