Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: GROOVY-6516

...

We can also use the '+' and '<<' operators to add elements to the map. Note that '<<' produces a new modifies the map while '+=' modifies the creates a new map:

Code Block
languagegroovy
def map4a = [:]
def map5a = map4a
assert map5a.is(map4a)
map4a << ['b':'b value']
assert map5a.is(map4a)
map4a+= ['a':'a value'] // map4a is not the original map4a anymore
assert !map5a.is(map4a)
assert map4a == [b:'b value', a:'a value']
assert map5a == [b:'b value']

...