-2

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.

Freeman
  • 232
  • 1
  • 2
  • 11

1 Answers1

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