gradle-baseline icon indicating copy to clipboard operation
gradle-baseline copied to clipboard

Rewriting lambdas to method references can produce ambiguous code that doesn't compile

Open jackwickham opened this issue 4 years ago • 1 comments

What happened?

If a method has two overloads, one for Function and one for BiFunction, it's possible for the rule to rewrite lambdas to produce ambiguous code. x -> y.get(x) is unambiguous, but y::get may be ambiguous if there are multiple variants of get.

What did you want to happen?

It shouldn't rewrite those lambdas, or rewriting them should include the cast required to make it unambiguous.

jackwickham avatar Jun 05 '20 18:06 jackwickham

The issue is actually with the receiver of the lambda being overloaded, not with the lambda itself. We could verify that there isn't an overload to avoid the problem. In practice I've only seen this with KeyedStream which in generally deprecated in favour of EntryStream

ferozco avatar Jun 05 '20 18:06 ferozco