I am trying to chain the calls/results of the methods to the next call. I get compile time error methodE because if am not able to get the reference of objB from the previou
You should use thenCompose, which is an asynchronous mapping, as opposed to thenApply, which is synchronous. Here's an example that chains two future-returning functions:
public CompletableFuture getStringAsync() {
return this.getIntegerAsync().thenCompose(intValue -> {
return this.getStringAsync(intValue);
});
}
public CompletableFuture getIntegerAsync() {
return CompletableFuture.completedFuture(Integer.valueOf(1));
}
public CompletableFuture getStringAsync(Integer intValue) {
return CompletableFuture.completedFuture(String.valueOf(intValue));
}
With thenApply you don't return a future. With thenCompose, you do.