1. 程式人生 > >Java中 Finally的解析

Java中 Finally的解析

finally的

public class FinallyTest2 {

    public static void main(String[] args) {
        System.out.println(new FinallyTest2().test());
    }

    @SuppressWarnings("finally")
    public int test()
    {
        int x = 1;
        try{
            ++x;
            int z = x/0;
            return x;
        }catch(Exception e){
            ++x;
            return x;
        }finally{
            ++x;
            //return x;
        }
        
    }
}

列印結果為  3