1

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;
        }
  }
seenimurugan
  • 464
  • 4
  • 19
  • 3
    As of Java 8, E inferred as RuntimeException. [Already answered here](http://stackoverflow.com/questions/31316581/a-peculiar-feature-of-exception-type-inference-in-java-8) – seenimurugan Dec 29 '16 at 13:38
  • 1
    So you are flagging yourself as a duplicate, that's first :) – AxelH Dec 29 '16 at 13:52

0 Answers0