如何通过使用lambda在Groovy中创建java.concurrent.Callable对象?

时间:2018-12-17 15:20:45

标签: java groovy

我发现我做不到

ExecutorService executorService = Executors.newSingleThreadExecutor()


Callable<String> stringCallable = {
    "hello world"
} as Callable<String>


Future<String> f = executorService.submit(stringCallable)

println f.get()
executorService.shutdown()

输出为:

null

但是当我直接跑步时:

println stringCallable.call()

输出为:

"hello world"

0 个答案:

没有答案