I can't get my head around the difference between thenApply(
) and thenCompose()
.
So, could someone provide a valid use case?
From the Java docs:
thenApply(Function<? super T,? extends U> fn)
Returns a new CompletionStage
that, when this stage completes
normally, is executed with this stage's result as the argument to the
supplied function.
thenCompose(Function<? super T,? extends CompletionStage<U>> fn)
Returns a new CompletionStage
that, when this stage completes
normally, is executed with this stage as the argument to the supplied
function.
I get that the 2nd argument of thenCompose
extends the CompletionStage where thenApply
does not.
Could someone provide an example in which case I have to use thenApply
and when thenCompose
?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…