假设这个:
ExecutorService service = ...; // somewhere in the code the executorService is used this way: service.submit(() -> { ... });
lambda表达式默认为Callable
.
有没有办法让它实例化Runnable
?
谢谢你的帮助.
您可以将其声明为Runnable,或使用强制转换:
Runnable r = () -> { ... }; executorService.submit(r);
要么
executorService.submit((Runnable) () -> { ... });