且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在地图内写DSL地图与闭合groovy,

更新时间:2023-11-18 12:34:46

如何在上面的地图例子中写一个DSL?这里是打印内部映射的键和值的插图。尝试此操作:

Here is an illustration of printing the keys and values of the inner map. Try this:

map1=new HashMap()
map2=new HashMap()
map2.put("1","one")
map1.put("map2",map2) 

map1.each{ entry1 ->
    def innerMap = entry1.value
    innerMap.each { entry2 ->
        println "key is ${entry2.key}"
        println "value is ${entry2.value}"
    }
}