Could someone explain why the first cast does not give a CCE ?
public class Test {
public static void main(String[] args) throws Throwable {
Test.<RuntimeException>throwIt(new Exception());
}
@SuppressWarnings("unchecked")
private static <T extends Throwable> void throwIt(Throwable throwable) throws T {
throw (T) throwable; // no ClassCastException
throw (RuntimeException) throwable; // ClassCastException(as it should be)
}
}
P.S. Comment one cast (otherwise it won't compile).