【发布时间】:2018-05-03 02:46:04
【问题描述】:
我有一个字符串列表如下。
List l = ["1","2","3"]
我有一个如下的课程。
class person {
String name
}
我想从 List l 创建一个人员对象列表。
我尝试过使用 groovy list collect 但我无法这样做。
这是我的代码。
class testJsonSlurper {
static void main(String[] args) {
List l = ["1","2","3"]
def l2 = l.collect { new person(it) }
println(l2)
}
}
但我收到以下错误。
Exception in thread "main" groovy.lang.GroovyRuntimeException: Could not find matching constructor for: testJsonSlurper$person(java.lang.String)
【问题讨论】: