July 2013
Intermediate to advanced
370 pages
8h 27m
English
In the previous sections, we saw how to define and use closures. In this section, we’ll talk about how to send multiple parameters to closures.
it is the default name for a single parameter
passed to a closure. We can use it as long as we know that only
one parameter is passed in. If we have more than one parameter passed, we
need to list those by name, as in this example:
| UsingClosures/ClosureWithTwoParameters.groovy | |
| | def tellFortune(closure) { |
| | closure new Date("09/20/2012"), "Your day is filled with ceremony" |
| | } |
| | tellFortune() { date, fortune -> |
| | println "Fortune for ${date} is '${fortune}'" |
| | } |
The method
tellFortune calls its closure with two parameters, namely an instance of ...
Read now
Unlock full access