Is there an interface in Java similar to the Callable
interface, that can accept an argument to its call method?
Like so:
public interface M
I just had the same issue. you can wrap any method to return a callable, and execute it's returned value. i.e.
main {
Callable integerCallable = getIntegerCallable(400);
Future future = executor.submit(integerCallable);
}
private Callable getIntegerCallable(int n) {
return () -> {
try {
TimeUnit.SECONDS.sleep(n);
return 123;
} catch (InterruptedException e) {
throw new IllegalStateException("task interrupted", e);
}
};
}