public class Unchecker {
public static void main(String[] args) {
throwUnchecked(new java.io.IOException());
}
private static void throwUnchecked(Exception exception) {
Unchecker.<RuntimeException>throwIt(exception);
}
private static <E extends Exception> void throwIt(Exception e) throws E {
throw (E)e;
}
}
In the code above, the main method doesn't declare an checked IOExcecption, but it throws it nevertheless:
$ java UncheckerAnd as a funny sidenote: the compiler prevents you from handling this exception with a regular "catch" clause...
Exception in thread "main" java.io.IOException
at Unchecker.main(Unchecker.java:4)
Type erasure FTW ;)