I expected the below code sample to fail compilation(Unhandled exception in main method) but it compiles successfully in Java 1.8. How <E extends Throwable>
becomes un-checked exception?
public class Test {
public static void main(String[] args) {
throwAsUnchecked(new Exception("Testing new checked exception"));
}
@SuppressWarnings("unchecked")
private static <E extends Throwable> void throwAsUnchecked(Exception exception) throws E {
throw (E) exception;
}
}