Common Groovy Methods

Collection:

 

Arrays:

  • initialization = []

  • shift << operator

  • the in operator

 

Groovy Maps:

  • initialization = [:]

  • index[“operator”]

  • dot.operator 

 

Closures:

  • Closure c1 = { it }

  • Closure c2 = { multiple, parameters -> ... }

  • Closure c3 = { return statementIsOptional }

  • assert a.foo({ bar(it) }) == a.foo { bar it }

Boolean:

  • assert null == false

  • assert 0 == false

  • assert “” == false

  • assert [] == false

  • assert new Object() == true

  • assert 123 == true

  • assert “Hello” == true

  • assert [1, 2, 3] == true

 

Groovy Syntax:

  • GString g = “Double quoted interpolated ${strings}”

  • String s = ‘single quotes strings’

  • def keyword closure { it }

  • *spreadOperator

  • safe?.navigation?.operator

  • the as Operator

  • BigDecimal type

 

Found an issue in documentation? Write to us.