When declaring a closure we can query it for the number of accepted parameters using:
Closure#getMaximumNumberOfParameters()
So for example:
def closure = { String param ->
}
println(closure.maximumNumberOfParameters)
Will output:
1
Why does the method declare the number of parameters as a maximum rather than a constant?
In what situation will the return value of this method differ from the actual number of parameters declared in the closure?
Default parameters?
def closure = { String param = 'something' ->
}
So you can technically call
closure()
And
closure('something else')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With