最後在Java 8中使用CompletableFuture dealio。我得到一個我不太瞭解的編譯錯誤(在我的IDE中)。Java 8 CompletableFuture.thenApply()
我已經得到了我想要追加到一個URL,然後異步調用每個URL標識的List<String>
。到目前爲止,我只有這幾種方法。
private void process(List<String> identifiers) {
List<CompletableFuture<String>> futures = identifiers.stream()
.map(CompletableFuture.thenApply(this::sendRequest))
.collect(toList());
}
private void sendRequest(String s) {
// do some URL building and append the string to the end of the url.
// then call it, don't care about result yet
}
我得到的編譯器錯誤是在第一個方法的this::sendRequest
片。這是抱怨我的班級沒有定義sendRequest(Object)
方法。
但我認爲通過鍵入identifiers
我不需要擔心我的拉姆達符號呼叫類型?我甚至不知道如何用::
運算符指定類型。也許我不應該使用::
運營商?我很困惑。
'CompletableFuture.thenApply'我不知道靜態的'thenApply'方法。 – zeroflagL
可悲的是我甚至爲了CompletableFuture拉起了javadoc,並沒有注意到這一點。可能是因爲試圖同時學習lambda函數和CompletableFutures。 – Justin