Other |
---|
tbdUnresolved |
Relates :
|
|
Relates :
|
|
Relates :
|
|
Relates :
|
|
Relates :
|
Reading from JLS 15.12.2.6: "The result type of the chosen method is determined as follows: [...] o Otherwise, if unchecked conversion was necessary for the method to be applicable then the result type is the erasure (§4.6) of the method's declared return type.[...]" Moreover "The exception types of the throws clause of the chosen method are determined as follows:[...] * If unchecked conversion was necessary for the method to be applicable then the throws clause is composed of the erasure (§4.6) of the types in the method's declared throws clause." which means that the following programs should *not* compile Example 1. class Test<X> { X m(Class<X> c) {return null;} X x = m((Class)String.class); } Example 2. class Test { <T extends Throwable> void foo(Class<T> c, T t) throws T {} void test(Exception e) { try { foo((Class)String.class, e); } catch (Exception t) {} } } Example 3. class Test<T extends Throwable> { void foo(Class<T> c, T t) throws T {} void test(Exception e) { try { new Test<Exception>().foo((Class)String.class, e); } catch (Exception t) {} } }
|