Bug in overload disambiguation / inference
Sam Pullara
spullara at gmail.com
Sun Feb 23 10:31:23 PST 2014
The issues center around some overloads that the library has:
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) {}
(full code here: https://gist.github.com/spullara/9175196)
Calling the method like this:
run(t -> t.toString())
causes an assertion error in the compiler (b129). I'm assuming that is just
a bug. The problem I run into is when you call it like:
run((O t) -> t.toString())
which results in
java: reference to run is ambiguous
both method <T,V>run(spullara.ExceptionInferenceBug.Function<? super
spullara.ExceptionInferenceBug.O,V>) in spullara.ExceptionInferenceBug and
method <T,V>run(spullara.ExceptionInferenceBug.PartialFunction<? super
spullara.ExceptionInferenceBug.O,V>) in spullara.ExceptionInferenceBug match
However, if the run methods are defined as:
static <T, V> void run(Function<O, V> function) {}
static <T, V> void run(PartialFunction<O, V> function) {}
It works fine. Any ideas? Seems like the same rules should apply.
Sam
More information about the lambda-dev
mailing list