假设这样:
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) () -> { ... });
关于java - 消除 lambda 中函数接口(interface)的歧义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34671292/