Skip to content

Instantly share code, notes, and snippets.

@spullara
Last active August 29, 2015 13:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save spullara/9175196 to your computer and use it in GitHub Desktop.
Save spullara/9175196 to your computer and use it in GitHub Desktop.
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