请告诉我以下情况之间的区别:
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)
有编译错误