3 ms·
> Now we will go through different ways to call method which accepts closure: 1. method accepts 1 parameter - closure myMethod(myClosure) 2. if m
by vorg 11y ago
> Now we will go through different ways to call method which accepts closure:
1. method accepts 1 parameter - closure
myMethod(myClosure)
2. if method accepts only 1 parameter - parentheses can be omitted
myMethod myClosure
3. I can create in-line closure
myMethod {println 'Hello World'}
4. method accepts 2 parameters
myMethod(arg1, myClosure)
5. or the same as '4', but closure is in-line
myMethod(arg1, { println 'Hello World' })
6. if last parameter is closure - it can be moved out of parentheses
myMethod(arg1) { println 'Hello World' }
When I first used Groovy back in 2004, all this seemed cool at the time, though this was before they added syntax style 2 for Groovy 1.7. Now all these choices just seem ridiculous.