Groovy Elvis Operator
//Groovy supports 'The Elvis Operator' too!
//Instead of using the ternary operator:
displayName = user.name ? user.name : 'Anonymous'
//We can write it:
displayName = user.name ?: 'Anonymous'
//Groovy supports 'The Elvis Operator' too!
//Instead of using the ternary operator:
displayName = user.name ? user.name : 'Anonymous'
//We can write it:
displayName = user.name ?: 'Anonymous'
Comments
Post a Comment