What is the “?:” operator used for in Groovy?

Just to add some more insight, the “?:” operator is known as the binary operator or commonly referred to as the elvis operator. The following code examples all produce the same results where x evaluates to true according to Groovy Truth

// These three code snippets mean the same thing. 
// If x is true according to groovy truth return x else return y
x ?: y

x ? x : y  // Standard ternary operator.

if (x) {
  return x
} else {
  return y
}

Click here for more info on Elvis Operator

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)