Difference between thenAccept and thenApply

You need to look at the full method signatures:

CompletableFuture<Void>     thenAccept(Consumer<? super T> action)
<U> CompletableFuture<U>    thenApply(Function<? super T,? extends U> fn)

thenAccept takes a Consumer and returns a T=Void CF, i.e. one that does not carry a value, only the completion state.

thenApply on the other hand takes a Function and returns a CF carrying the return value of the function.

Leave a Comment

tech