Is it possible to include statements with expressions with Groovy's conditional operator? This is what I'm doing now, and I want break this down in a single conditional statement with the println statements...
if(!expired){
println 'expired is null'
return true
}
else if( now.after(expired)){
println 'cache has expired'
return true
}
else
return false
Converted into single statement...
return (!expired) ? true : (now.after(expired)) ? true : false
...would like to do something like this for debugging purposes...
return (!expired) ? println 'expired is null' true : (now.after(expired)) ? println 'cache has expired' true : false
As GrailsGuy said in the other answer, use closures:
def expired= false, expired2= true
return (!expired) ?
{println "expired is null"; true}() :
(expired2) ? {println "cache has expired"; true}() : false
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