From Groovy point of view Elvis operator(?:) is used to return the value of the left expression if its evaluates to true, but the value of the right expression otherwise. But what happens if the code is like this:
age <=> other.age ?: lastName <=> other.lastName ?: firstName <=>
other.firstName
How does it executes the above code?
Thanks for the reply.
From http://docs.codehaus.org/display/GROOVY/JN2535-Control,
<=>has higher precedence than?:. This means that…becomes something like…
which ends up as -1. Since
0 ?: -1 == -1and-1 ?: 0 == -1.Hope that makes sense. Looks like the example is meant to be used to carry out sorting on age, then last name, then first name.