I have this piece of code:
CompletableFuture
.supplyAsync(() -> {
return smsService.sendSMS(number);
}).thenApply(result -> {
LOG.info("SMS sended " + result);
});
but I got a compilation error:
The method
thenApply(Function<? super Boolean,? extends U>)in the typeCompletableFuture<Boolean>is not applicable for the arguments((<no type> result) -> {})
You want to use
thenAcceptnotthenApplythenApplytakes aFunctionwhich is of the formthenAccepttakes aConsumerwhich is of the formThe lambda you provided does not have a return value; it is void. Because a generic type parameter cannot be void your lambda cannot be casted as a
Functioninterface. On the other hand, theConsumerhas a void return type which the lambda could satisfy.