finally 遮蔽返回值 甚至吞掉异常

public class Demo01 {
    
    
    public int method(){
    
    
        int[] arr = new int[2];
        try{
    
    
            int a = arr[5];
        }finally {
    
    
            return 999;
        }
    }

    public static void main(String[] args) {
    
    
        Demo01 d = new Demo01();
        System.out.println(d.method());
    }
}

打印了 999,吞掉了异常

猜你喜欢

转载自blog.csdn.net/Mason97/article/details/108429345