java - CompletableFuture allof timeout handling
黄舟
黄舟 2017-06-12 09:24:13
0
1
1792

The effect you want to achieve: If the future collection does not return within 3 seconds, the completed future will be extracted.

Compilation error, "Cannot infer functional interface type."

黄舟
黄舟

人生最曼妙的风景,竟是内心的淡定与从容!

reply all(1)
世界只因有你

The problem with the compilation error is that the subject did not pay too much attention. This can be easily checked.
You can see the red area of ​​the error report, which is the second parameter of the applyToEither method. Then check it applyToEither Parameter format of method

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

The second parameter is a Function. What Function requires is to return a result based on a parameter. However, the question clearly states that there are no parameters. It is written as a Supplier. Of course, the parameter type is not Meet the requirements of method applyToEither

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!