首页 > 解决方案 > CompletedStage.completedFuture VS CompletedStage.completedStage

问题描述

我看到 Java9 CompletedStage.completedStage() 几乎等于 CompletedStage.ompletedFuture()

当我们必须返回时

CompletionStage<Void>

我们可以同时返回。CompletedFuture.completedFuture() 未被弃用,并且在 CompletedStage() 的 Java 文档中写入

Returns a new CompletionStage that is already completed with the given value and supports only 
those methods in interface CompletionStage.

那么真正的区别是什么,什么时候必须使用一个而不是另一个?什么时候必须返回 Void 比较好?

CompletedFuture.completedFuture(null)

或者

CompletedFuture.completedStage(null)

标签: javaasynchronousjava-9completion-stage

解决方案


推荐阅读