def foo(map,name) { println(map) } foo("bar",hi: "bye")
将打印
[hi:bye]
现在我有一张我希望传递给foo的先前地图.在伪代码中,类似于:
def otherMap = [hi: "world"] foo("bar",hi: "bye",otherMap*)
所以它打印
[hi:world]
这当然不起作用.
此外,尝试仅传递地图混合参数的顺序:
def otherMap = [hi: "world"] foo("bar",otherMap)
将打印
bar
我怎样才能解决这个问题?
解决方法
您正在寻找传播地图运算符.
def foo(map,hi: "bye") def otherMap = [hi: "world"] foo("bar",*:otherMap) foo("bar",*:otherMap,hi: "bye")
打印:
["hi":"bye"] ["hi":"world"] ["hi":"bye"]