Duplicate :
|
|
Relates :
|
javac apparently does some partial checking of lambda bodies in nested invocations during overload resolution, and uses the results to consider some methods inapplicable. This is incorrect -- the nested lambda body should not influence applicability at all. <T> T apply(UnaryOperator<T> op, T arg) { return op.apply(arg); } class B { B x() { return this; } } class C {} void m(B arg) { System.out.println("B"); } void m(C arg) { System.out.println("C"); } m(apply(arg -> arg.x(), null)); // ambiguous, as expected m(apply(arg -> new B(), null)); // expected: ambiguous; actual: chooses m(B) (I believe this is a holdover from earlier overload resolution prototypes, which were designed to make use of partial information in the lambda body.)