How to create a completed future in java

前端 未结 6 882
不思量自难忘°
不思量自难忘° 2021-02-06 20:12

What is the best way to construct a completed future in Java? I have implemented my own CompletedFuture below, but was hoping something like this that already exist

6条回答
  •  逝去的感伤
    2021-02-06 20:41

    In Java 8 you can use the built-in CompletableFuture:

     Future future = CompletableFuture.completedFuture(value);
    

提交回复
热议问题