Return CompletableFuture or CompletableFuture<?>?

后端 未结 4 1478
予麋鹿
予麋鹿 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:19

    Would it be better to return CompletableFuture or CompletableFuture

    Is there a reason to prefer one or the other, or are they interchangeable?

    There are three contexts which code may affect:

    • Runtime - generics have no implication on it.
    • Compile - I can't imagine a case where some method will accept Future but won't accept Future.
    • Development - if Future's result have no meaning, then it is a good practice to say about that to the users through the declaration.

    So Future is more preferable.

提交回复
热议问题