Heim  >  Fragen und Antworten  >  Hauptteil

java – CompletableFuture Allof-Timeout-Behandlung

Der Effekt, den Sie erzielen möchten: Wenn die zukünftige Sammlung nicht innerhalb von 3 Sekunden zurückkehrt, wird die abgeschlossene Zukunft extrahiert.

Kompilierungsfehler: „Funktionsschnittstellentyp kann nicht abgeleitet werden.“

黄舟黄舟2661 Tage vor1760

Antworte allen(1)Ich werde antworten

  • 世界只因有你

    世界只因有你2017-06-12 09:26:13

    编译报错的问题,是题主没有太仔细哈,这个很容易就检查出来了
    可以看到这个报错标红的地方,在applyToEither方法的第二个参数上,那查看一哈applyToEither方法的参数格式

    public <U> CompletableFuture<U> applyToEither(
            CompletionStage<? extends T> other, Function<? super T, U> fn) {
            return orApplyStage(null, other, fn);
        }

    第二个参数是一个FunctionFunction要求的是根据一个参数返回一个结果,而题主写的很明显,是没有参数的啊,写成了一个Supplier,当然参数类型是不符合方法applyToEither的要求噻

    Antwort
    0
  • StornierenAntwort