7

当我在控制台(groovy 2.1.3)中运行以下代码时:

strings =  [ "butter", "bread", "dragon", "table" ]
strings.eachParallel{println "$it0"}

我得到:

groovy.lang.MissingMethodException: No signature of method: java.util.ArrayList.eachParallel() is applicable for argument types: (ConsoleScript40$_run_closure1) values: [ConsoleScript40$_run_closure1@a826f5]

谁能告诉我我做错了什么?

4

1 回答 1

10

我认为您缺少设置。尝试

@Grab(group='org.codehaus.gpars', module='gpars', version='1.0.0')
import groovyx.gpars.GParsPool

GParsPool.withPool {
    def strings =  [ "butter", "bread", "dragon", "table" ]
    strings.eachParallel { println it }
}
于 2013-06-05T02:54:50.987 回答