我已经看到了他们每个人的例子,但我需要知道的是,到底是什么在深深的差别,因为有时候我觉得我可以同时使用它们来得到相同的结果,所以我想知道,这样我可以选择正确的一?
什么是使用他们每个人的利益?
像这样的例子两部作品:
public CompletionStage<Result> getNextQueryUUID() {
return CompletableFuture.supplyAsync(() -> {
String nextId = dbRequestService.getNextRequestQueryUUID();
return ok(nextId);
}, executor);
}
public CompletableFuture<Result> getNextQueryUUID() {
return CompletableFuture.supplyAsync(() -> {
String nextId = dbRequestService.getNextRequestQueryUUID();
return ok(nextId);
}, executor);
}
这个例子运行
Play framework
。
CompletionStage<T>
是其中的接口CompletabeFuture<T>
是唯一的实现类此接口。通过查看Java说明文件CompletionStage<T>
,你会发现CompletionStage接口提供用于采取一个CompletionStage并将其转换成另一种方法CompletionStage
。然而,由CompletionStages返回这些对象作为自己的实际CompletabeFuture<T>
对象。
因此,使用CompletabeFuture<T>
是一种同样的事情使用CompletionStage<T>
,但后者可以作为对未来的基本接口为可能的新类以及作为许多种下降目标类型,就像我们倾向于做的List<Integer> integerList = new ArrayList<>();
,而不是ArrayList<Integer> integerList = new ArrayList<>();
您可以阅读帖子介绍CompletionStage和CompletableFuture的更多细节。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句