Please, tell me difference between the next situations :
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
}
}
There is no compilation error in this case
AND
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
}
}
There is compilation error