Generics: Why can’t the compiler infer the type arguments in this case?

UPDATE: This answer was written over ten years ago; since then the type inference specification and implementation have been updated several times including changes to how constraints are used during inference. This answer should be considered of historical interest only; consult a recent copy of the C# specification to see how type inference works in … Read more

A peculiar feature of exception type inference in Java 8

The T of sneakyThrow is inferred to be RuntimeException. This can be followed from the langauge spec on type inference (http://docs.oracle.com/javase/specs/jls/se8/html/jls-18.html) Firstly, there’s a note in section 18.1.3: A bound of the form throws α is purely informational: it directs resolution to optimize the instantiation of α so that, if possible, it is not a … Read more