Community
Participate
Working Groups
From https://bugs.openjdk.java.net/browse/JDK-8170361 Better disambiguation for functional expression Overload resolution was completely restructured in Java SE 8 to allow deeper interactions with type inference. In Java SE 8, not all the argument expressions in a method call are subject to the applicability test; only those that are pertinent to applicability. Lambda and method references can belong to both categories; explicit lambdas and exact method refs are pertinent to applicability, whereas implicit lambdas and inexact method refs are not. When an expression is not pertinent to applicability, the precision of the applicability test is much reduced - such expressions are not subject to the full test (i.e. compatibility against target), but are subject to a much looser check, called potential compatibility, which verifies only that: the arity of the lambda/method reference matches that of the target function type a value (resp. void)-compatible lambda/method reference is used against a value (resp. void)-compatible function type Specifically, the compiler is not allowed to do: attribution of the lambda body overload resolution of the method reference And as a result, the compiler's ability to rule out inapplicable candidates is severely impaired. This was a deliberate compromise to avoid brittleness (i.e., errors in a lambda body could drive overload resolution decisions, and therefore changes in the body of a lambda could affect overload resolution decisions) and to avoid a combinatorial explosion of the cost of type checking. However, there are minor improvements that can be made within these constraints, that enables better applicability checking. This would enable us to eliminate some accidental ambiguity errors that tend to come up quite regularly in real Java code. Consider the following example: m(Predicate<String> ps) { ... } m(Function<String, String> fss) { ... } m(s -> false) //ambiguous For the user, it's obvious which overloaded method should be selected here - the lambda returns false, so a Function<String, String> is clearly incompatible. But for the compiler, the lambda is not pertinent to applicability, both methods are applicable, none is more specific, and so an ambiguity error ensues.
This bug hasn't had any activity in quite some time. Maybe the problem got resolved, was a duplicate of something else, or became less pressing for some reason - or maybe it's still relevant but just hasn't been looked at yet. If you have further information on the current state of the bug, please add it. The information can be, for example, that the problem still occurs, that you still want the feature, that more information is needed, or that the bug is (for whatever reason) no longer relevant. -- The automated Eclipse Genie.
If / when this JDK issue will be picked up again, it would be great to have some sharable description concerning @SuppressWarnings("overloads") which seems to be very closely related. See bug 559000 and also https://stackoverflow.com/questions/29136053/warning-overloads-method-m1-is-potentially-ambiguous-with-method-m2/29137665#comment125451535_29137665