JDK-8033483 : Should ignore nested lambda bodies during overload resolution
  • Type: Bug
  • Component: tools
  • Sub-Component: javac
  • Affected Version: 8,9
  • Priority: P4
  • Status: Closed
  • Resolution: Fixed
  • Submitted: 2014-02-03
  • Updated: 2016-01-22
  • Resolved: 2014-07-09
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 8 JDK 9
8u40Fixed 9 b23Fixed
Related Reports
Duplicate :  
Relates :  
Description
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.)