Ich bin neu in CompletableFuture, hier ein einfaches ist, würde ichWas ist falsch bei der Verwendung von CompleableFuture?
CompletableFuture.supplyAsync(()-> {System.out.println("async");});
Wenn ich zu kompilieren versuchen ausprobieren, gab es den Fehler
Error:(23, 26) java: no suitable method found for supplyAsync(()->{ Syst[...]"); })
method java.util.concurrent.CompletableFuture.<U>supplyAsync(java.util.function.Supplier<U>) is not applicable
(cannot infer type-variable(s) U
(argument mismatch; bad return type in lambda expression
missing return value))
method java.util.concurrent.CompletableFuture.<U>supplyAsync(java.util.function.Supplier<U>,java.util.concurrent.Executor) is not applicable
(cannot infer type-variable(s) U
(actual and formal argument lists differ in length))
Ich frage mich, was mit dem falsch über?
Nun du nichts zurückkehr - welche Art von „Lieferant“ glaubst du, du vorbei? –
Sie vermissen die Rückgabe https://docs.oracle.com/javase/8/docs/api/java/util/concurrent/CompletableFuture.html#supplyAsync-java.util.function.Supplier- –
Sie sollten 'CompleableFuture verwenden .runAsync (() -> System.out.println ("async")); 'stattdessen. – Flown