18 lines
569 B
Java
18 lines
569 B
Java
package bunny.async;
|
|
|
|
import java.util.concurrent.CompletableFuture;
|
|
|
|
public class CompletableFutureTest6 {
|
|
public static void main(String[] args) {
|
|
CompletableFuture<Integer> future = CompletableFuture.supplyAsync(() -> 42);
|
|
|
|
// 对结果调用函数并执行返回 Future
|
|
CompletableFuture<String> composedFuture = future
|
|
.thenCompose(result -> CompletableFuture.supplyAsync(() -> "Result: " + result));
|
|
|
|
// 拿到返回值
|
|
String result = composedFuture.join();
|
|
System.out.println(result);
|
|
}
|
|
}
|