Reputation: 27385
From the documentation, 13.5.5:
When the last parameter of a method is a closure, you can place the closure after the method call
Ok, I tried that, but it didn't exactly work as I was supposed. Consider the following code:
def repostiory_closure = {
mavenCentral()
}
repositories{ //OK
mavenCentral()
}
repositories(){ //OK
mavenCentral()
}
repositories repostiory_closure //OK
repositories() repostiory_closure //compile-time error
So we can put the only a closure literal after a method call, but the variable of a Closure
type. Is that right?
Upvotes: 0
Views: 36
Reputation: 7916
What you need to do is put the closure as an argument of the method call like so:
repositories(repostiory_closure)
So because the last argument is a closure the method can be called inline as above.
Upvotes: 2