// long form
String sayHello(String name){
"Hello, ${name ? name : 'stranger'}."
}
// elvis
String sayHello(String name){
"Hello, ${name ?: 'stranger'}."
}
Notice that the "elvis" format omits the "true" term because the original comparison value is to be used in the "true" case. If name
is Groovy true
, then it will be returned as the value of the expression.