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."
世界只因有你2017-06-12 09:26:13
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