我有一个代码:
CompletableFuture<Integer> c1 = new CompletableFuture<Integer>()
.thenApply((data) -> data * 2);
c1.thenAccept(System.out::println);
c1.complete(20);
CompletableFuture<Integer> c2 = new CompletableFuture<>();
c2.thenApply(data -> data * 2)
.thenAccept(System.out::println);
c2.complete(20);
输出:
20 40
问题:
为什么 c1 和 c2 之间的输出存在差异?
为什么需要通过调用在 c1 中重复未来类型:
新的 CompletableFuture<整数>()
达令说
相关分类