Executors.newFixedThreadPool(3).submit(() -> {doSmth();});
“模糊方法调用。在ExecutorService中提交(Callable)并在ExecutorService匹配中提交(Runnable)。”
如何解决?我知道我可以使用匿名类,但我想使用Function。
答案 0 :(得分:13)
Executors.newFixedThreadPool(3).submit(() -> 1); //Callable
Executors.newFixedThreadPool(3).submit(() -> {doSmth();}); //Runnable
答案 1 :(得分:3)
在含糊不清的情况下,明确提供类型:
Runnable runnable = () -> {doSmth();}
submit(runnable);
//or:
submit((Runnable) () -> {doSmth();});