-
Bug
-
Resolution: Fixed
-
P2
-
8
-
b13
-
Verified
Issue | Fix Version | Assignee | Priority | Status | Resolution | Resolved In Build |
---|---|---|---|---|---|---|
JDK-8035431 | 9 | Vicente Arturo Romero Zaldivar | P2 | Closed | Fixed | b11 |
JDK-8045150 | 8u25 | Vicente Arturo Romero Zaldivar | P2 | Resolved | Fixed | b01 |
JDK-8052589 | emb-8u26 | Vicente Arturo Romero Zaldivar | P2 | Resolved | Fixed | b17 |
A lambda expression (15.27) is potentially compatible with a functional interface type (9.8) if all of the following are true:
- The arity of the targeted type's function type is the same as the arity of the lambda expression.
- If the targeted type's function type has a void return, then the lambda body is either a statement expression (14.8) or a void-compatible block (15.27.2).
- If the targeted type's function type has a (non-void) return type, then the lambda body is either an expression or a value-compatible block (15.27.2).
The current javac implementation seems to only take the lambda expression's arity into account, completely ignoring the lambda body.
Example:
interface I {
String foo(String [] x, String y);
}
interface J {
void foo(int x, int y);
}
public class X {
static void goo(J j) {
System.out.println("goo(J)");
}
static void goo(I i) {
System.out.println("goo(I)");
}
public static void main(String[] args) throws InterruptedException {
goo((x, y) -> { return x[0] += 1; }); // expected: print goo(I); actual: ambiguity error
}
}
Originally reported on lambda-dev@openjdk.java.net:
http://mail.openjdk.java.net/pipermail/lambda-dev/2013-November/011394.html
- backported by
-
JDK-8045150 Should always use lambda body structure to disambiguate overload resolution
- Resolved
-
JDK-8052589 Should always use lambda body structure to disambiguate overload resolution
- Resolved
-
JDK-8035431 Should always use lambda body structure to disambiguate overload resolution
- Closed
- duplicates
-
JDK-8038485 Inconsistent ambiguous warning for overloaded methods with functional interfaces
- Closed
-
JDK-8042738 Implicitly-typed lambdas are incorrectly potentially applicable
- Closed
-
JDK-8043734 lambda ambiguous reference caused by RuntimeException
- Closed
- relates to
-
JDK-8005244 Implement overload resolution as per latest spec EDR
- Closed