小编Леш*_*кки的帖子

接下来的情况有什么区别

请告诉我以下情况之间的区别:

public class Test {
    private static < T extends Throwable > void doThrow(Throwable ex) throws T {
        throw (T) ex;
    }

    public static void main(String[] args) {
        doThrow(new Exception()); //it's ok
    }
}
Run Code Online (Sandbox Code Playgroud)

这种情况下没有编译错误

public class Test {
    private static < T extends Throwable > void doThrow(Throwable ex) throws Throwable {
        throw (T) ex;
    }

    public static void main(String[] args) {
        doThrow(new Exception()); //unhandled exception
    }
}
Run Code Online (Sandbox Code Playgroud)

有编译错误

java exception throwable

5
推荐指数
1
解决办法
115
查看次数

标签 统计

exception ×1

java ×1

throwable ×1