Search code examples
variablesgroovydefinition

What does [:] mean in groovy?


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

def foo=[:]

What does it mean?


Solution

  • [:] is shorthand notation for creating a Map.

    You can also add keys and values to it:

    def foo = [bar: 'baz']