If we have AsyncResponse response
variable we can write something like:
CompletableFuture#thenAccept(response::resume)
.
I don't understand how can we pass boolean resume(Object response)
method from AsyncResponse
class to thenAccept()
which takes Consumer
as parameter, because Consumer
return void
.
Asked
Active
Viewed 292 times
-2

Freeman
- 232
- 1
- 2
- 11
-
Can you try using thenApply(...)? – aydinugur Dec 26 '18 at 14:51
-
1"How can we pass..." - by ignoring the return value. – M. Prokhorov Dec 26 '18 at 14:55
1 Answers
2
The method reference will just ignore the return value. If you expand the method reference into an anonymous inner class, it would look like this:
completableFuture.thenAccept(new Consumer<Object>() {
@Override
public void accept(Object object) {
response.resume(object);
}
});

Wim Deblauwe
- 25,113
- 20
- 133
- 211
-
`completableFuture.thenAccept(response::resume);` would be enough. – Nikolas Charalambidis Dec 26 '18 at 16:53