Elvis operator is a shortcut to ternary operator. It is
used to assign some default value.
myOrganization = organization ? organization : "ABC
Corp"
We can rewrite the above statement using elvis operator
like below.
myOrganization = organization ?: "ABC Corp"
HelloWorld.groovy
organization = "" myOrganization = organization ?: "ABC Corp" println myOrganization
Output
ABC Corp
ABC Corp
No comments:
Post a Comment