【发布时间】:2017-03-24 00:22:39
【问题描述】:
我有一个 groovy 方法,它适用于map containing maps 的硬编码变量。我想做这样的地图作为参数传递。地图的数量也将vary。我试图实现的一个简单表示是这样的:
def name(Map p...) {
//code to loop through each of the maps
p.each { k ->
"${k.first}, ${k.last}"
//another loop with the internal map
something {
k.details.each { name, value ->
//some code
}
}
}
}
我需要传递的 Map of maps 示例如下:
def persons = [
[first: 'Jack', last: 'Smith', details: [gender: 'male', Age: 25]],
[first: 'Sean', last: 'Dean', details: [gender: 'male', Age: 26]]
]
那么接下来,我想调用类似的东西
name(persons)
我怎样才能做到这一点?到目前为止,我在 groovyConsole 中的测试并没有带我去任何地方......
【问题讨论】:
-
您介意解释一下您遇到的确切问题吗?
-
似乎传递了一个列表
name(persons),而不是方法中定义的映射。 -
是的,这似乎是一个原因......我忽略了它
标签: groovy