markdown-it
demo
Delete
Submit
clear
permalink
### CompletableFuture ```java import java.util.concurrent.CompletableFuture; public class CompletableFutureExample { public static void main(String[] args) { // 創建一個CompletableFuture並在另一個執行緒中執行一個供應器,返回字串"Hello" CompletableFuture<String> future = CompletableFuture.supplyAsync(() -> { return "Hello"; }).thenApplyAsync(result -> { // 使用thenApplyAsync方法對"Hello"進行處理,返回"Hello World" return result + " World"; }); // 當CompletableFuture完成後執行操作,印出結果"Hello World" future.thenAccept(result -> { System.out.println(result); // Hello World }); // 等待CompletableFuture完成 future.join(); } } ```
html
source
debug
Fork me on GitHub