How can I concisely set a default value for a value of a closure that is not populated?
Below I thought using the optional chaining operator would prevent throwing an exception, but I still got an exception.
myfunction {
FOO="myfoo"
BAZ="mybaz"
}
def myfunction(Closure body = {}) {
body()
foo = body?.FOO ?: "defaultFoo"
// getting exception since BAR isnt defined
bar = body?.BAR ?: "defaultBar"
println("foo=" + foo + " bar=" + bar)
}