Categories

Nov 12, 2019 in DevOps

Q: What Is Closure In Groovy?

1 Answer

Nov 12, 2019
A closure in Groovy is an open, anonymous, block of code that can take arguments, return

a value and be assigned to a variable. A closure may reference variables declared in its

surrounding scope. In opposition to the formal definition of a closure, Closure in the

Groovy language can also contain free variables which are defined outside of its

surrounding scope.

A closure definition follows this syntax:

{ [closureParameters -> ] statements }

Where [closureParameters->] is an optional comma-delimited list of parameters, and

statements are 0 or more Groovy statements. The parameters look similar to a method

parameter list, and these parameters may be typed or untyped.

When a parameter list is specified, the -> character is required and serves to separate the

arguments from the closure body
Click here to read more about DevOps
Click here to read more about Insurance

Related questions

Madanswer
Nov 12, 2019 in DevOps
Nov 12, 2019 in DevOps
Nov 12, 2019 in DevOps
Nov 12, 2019 in DevOps
...