In some situations the Java compiler is unable to determine the correct overload to call when using lambdas. See my Stackovervlow question for one example of the ambiguity problem. The ambiguity problem occurs for Function/Consumer overloads, but it also occurs for generic parameter/ArgumentMatcher overloads.
For example a lambda calling getPattern with overloads getPattern(Function<String, String> function) andgetPattern(Consumer<String> consumer) will fail to compile due to ambiguity. The same is true for the following overloads: getPattern(A, Function<A, String> function) and getPattern(ArgumentMatcher, Function<A, String> function).
My initial solution to the Function/Consumer problem is to follow the convention of naming all Function methods as case* and all Consumer methods as caze*. I'm not super happy about this, but I haven't come up with a better alternative so far.
I'm at more of a loss as to what to do for the A/ArgumentMatcher issue. I could drop the exact match APIs entirely and require matchers always, but this adds verbosity even when it's not needed.
If anyone has any thoughts on either of these ambiguity issues I am open to input.
In some situations the Java compiler is unable to determine the correct overload to call when using lambdas. See my Stackovervlow question for one example of the ambiguity problem. The ambiguity problem occurs for Function/Consumer overloads, but it also occurs for generic parameter/ArgumentMatcher overloads.
For example a lambda calling
getPattern
with overloadsgetPattern(Function<String, String> function)
andgetPattern(Consumer<String> consumer)
will fail to compile due to ambiguity. The same is true for the following overloads:getPattern(A, Function<A, String> function)
andgetPattern(ArgumentMatcher, Function<A, String> function)
.My initial solution to the Function/Consumer problem is to follow the convention of naming all Function methods as
case*
and all Consumer methods ascaze*
. I'm not super happy about this, but I haven't come up with a better alternative so far.I'm at more of a loss as to what to do for the A/ArgumentMatcher issue. I could drop the exact match APIs entirely and require matchers always, but this adds verbosity even when it's not needed.
If anyone has any thoughts on either of these ambiguity issues I am open to input.