Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
package spullara;
public class ExceptionInferenceBug {
interface Function<T, V> extends PartialFunction<T, V> {
V apply(T paramT);
interface PartialFunction<T, V> {
V apply(T paramT) throws Exception;
interface O {}
static <T, V> void run(Function<? super O, V> function) {}
static <T, V> void run(PartialFunction<? super O, V> function) {}
static <T, V> void run2(Function<O, V> function) {}
static <T, V> void run2(PartialFunction<O, V> function) {}
public static void main(String[] args) {
run(t -> t.toString()); // causes an assertion error
run((O t) -> t.toString()); // ambiguous
run((O t) -> { throw new Exception(); });
run2(t -> t.toString()); // works
run2((O t) -> { throw new Exception(); }); // ambiguous
run2((PartialFunction<O, Void>) (O t) -> { throw new Exception(); }); // works
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.