What does [:] mean in groovy?

das Keks picture das Keks · Apr 4, 2014 · Viewed 15k times · Source

While reading some groovy code of another developer I encountered the following definition:

def foo=[:]

What does it mean?

Answer

doelleri picture doelleri · Apr 4, 2014

[:] is shorthand notation for creating a Map.

You can also add keys and values to it:

def foo = [bar: 'baz']