Wednesday 6 April 2016

Groovy Map << [key: value] vs Map << [(key): value]

Note the difference between a key wrapped with () and without. If without parentheses, the key will be literal 'key'. With parentheses, the key is the value 100.

 def key = 100  
 def map = [:]  
 map << [key:2]  
 println map  
 map << [(key):2]  
 println map