第一张地图是默认选项[a: true, b: false]
。第二张地图 - 用户[a:false]
传递的选项。 Groovy是否有映射合并方法以获取[a: false, b:false]
?
在Groovy中实现它并不是问题。我问的是开箱即用的方法
答案 0 :(得分:151)
您可以使用加号:
assert [ a: true, b: false ] + [ a: false ] == [ a: false, b: false ]
或左移:
assert [ a: true, b: false ] << [ a: false ] == [ a: false, b: false ]
区别在于<<
adds the right hand map into the left hand map。当您使用+
时,constructs a new Map based on the LHS,并将右侧地图添加到其中