使用闭包 groovy 在地图内编写 DSL 地图,
使用闭包访问地图内的地图, 我有一个地图对象,其值是另一个地图对象 例如:- `
to access the data like this I can issue
def map = [name:"Gromit", likes:"cheese", id:1234]
def map2 =[map1:map]
map2.each{entry ->
println entry.key
entry.value.each {entry1 -> println entry1.key
println entry1.value
}
}
to access a single map i can issue
map.each{entry ->
println entry.key
println entry.value
}
'
如何以简单的任何提示为上面的地图示例编写 DSL?
Accessing map inside map with closure,
I have a map object the values is another map object
e.g:-
`
to access the data like this I can issue
def map = [name:"Gromit", likes:"cheese", id:1234]
def map2 =[map1:map]
map2.each{entry ->
println entry.key
entry.value.each {entry1 -> println entry1.key
println entry1.value
}
}
to access a single map i can issue
map.each{entry ->
println entry.key
println entry.value
}
'
How can I write a DSL for the above map example in simple any hint?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这是打印内部映射的键和值的示例。试试这个:
Here is an illustration of printing the keys and values of the inner map. Try this:
anish,我假设您正在寻找一种更短的方式来访问地图,这将是
map2.map1
。然后您可以使用map2.map1.name
来获取“Gromit”。如果您不希望以更短的方式获取地图,请指定更多信息。anish, I assume you look for a shorter way to access the map, this would be
map2.map1
. You can then usemap2.map1.name
to get "Gromit". If a shorter way to get the map was not your question, then please specify more.