I have a functional interface
import java.util.concurrent.Callable;
import java.util.concurrent.CompletableFuture;
@FunctionalInterface
public interface SubmitterCompletable extends Submitter {
@Override
<T> CompletableFuture<T> submit(Callable<T> task);
}
and two functions
import java.util.concurrent.Callable;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.Executor;
public final class CompletableFutureUtils {
public static <U> CompletableFuture<U> runAsync(Callable<U> callable) {
// ...
}
public static <U> CompletableFuture<U> runAsync(Callable<U> callable, Executor executor) {
// ...
}
}
and I want to create SubmitterCompletable
s from these functions using lambda expressions or method references. The first one works fine by using method references.
SubmitterCompletable submitterCompletable = CompletableFutureUtils::runAsync;
For the second one, however, I have to use a lambda expression to pass an Executor
and it doesn't work.
Executor executor = /* ... */;
SubmitterCompletable submitterCompletable = c -> CompletableFutureUtils.runAsync(c, executor);
// Illegal lambda expression: Method submit of type SubmitterCompletable is generic
My question is whether there is a valid lambda expression for this case, or do I have to create an anonymous class in this case?