I have the following situation, where the lambda expression i used to replace a working for loop does not work. Have no clue as to why this fails
public class Abc implements IAbc {
// some fields
...
// field i'm interested in
@Inject @Any
private Instance<HandlerInterface> handlers;
// more members
...
// method i'm interested in
@Override
public boolean hasHandler(List<Order> orders) {
for (Order anOrder : orders) {
for (HandlerInterface aHandler : handlers) {
// following canHandler() is implemented by each
// handler that implements the HandlerInterface
if(aHandler.canHandle(anOrder)) {
return true;
}
}
return false;
}
// rest of the class content
.....
}
So I was actually trying to replace the above code, within the method, with Lambdas (to which i'm new). The following was my replacement code
public boolean hasHandler(List<Order> orders) {
return orders.stream().anyMatch(order ->
Stream.of(handlers).map(Provider::get).anyMatch(handler ->
handler.canHandle(order)));
}
The above lambda expression fails at handler.canHandle with AmbiguousResolutionException. I can't find out why it works with the for loop and not with stream. Im sure im doing something wrong here - but have no clue as to what. Any help on this is greatly appreciated.
Provider::getreturn ?Provider::getstep that doesn’t exist in the loop code?