[英]Does Groovy have method to merge 2 maps?
First map is default options [a: true, b: false]
. 第一个映射是默认选项
[a: true, b: false]
。 Second map - options passed by user [a:false]
. 第二个地图-用户
[a:false]
传递的选项。 Does Groovy has maps merge method to obtain [a: false, b:false]
? Groovy是否有地图合并方法来获取
[a: false, b:false]
?
It's not problem to implement it in Groovy. 在Groovy中实现它不是问题。 I'm asking about method out of the box
我问开箱即用的方法
You can use plus: 您可以使用加号:
assert [ a: true, b: false ] + [ a: false ] == [ a: false, b: false ]
Or left shift: 或左移:
assert [ a: true, b: false ] << [ a: false ] == [ a: false, b: false ]
The difference is that <<
adds the right hand map into the left hand map . 区别在于
<<
将右手图添加到左手图中 。 When you use +
, it constructs a new Map based on the LHS , and adds the right hand map into it 当您使用
+
,它将基于LHS构造一个新的Map ,并将右侧的地图添加到其中
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.