Return CompletableFuture or CompletableFuture<?>?

后端 未结 4 1442
予麋鹿
予麋鹿 2021-01-30 12:35

I want to write an asynchronous method that returns a CompletableFuture. The only purpose of the future is to track when the method is complete, not its result. Would it be bett

4条回答
  •  佛祖请我去吃肉
    2021-01-30 13:16

    It is best to use CompletableFuture.

    According to this answer found by Sotirios Delimanolis, Future is a minor API flaw. In Java 6 the submit() method used a Future internally, and so its return type was set to Future. In Java 7 the implementation changed to use Future internally, but it was too late to change the API so the return value stayed as Future.

    Newer Java APIs use Future and CompletableFuture. Those are the examples we should follow.

    提交回复
    热议问题