First page Back Continue Last page Overview Image

Syntactic sugar: closure

Similar to a block in Ruby:

1.upto(4, { println it })

1.upto(4, { println "Number ${it}" })

3.times { println it }

3.times { println "Hello World ${it}" }

def squareIt = { int x ->

square = x**2

return square

}

assert squareIt(5) == 25