Link Details

Link 92993 thumbnail
User 111696 avatar

By bloid
via codecommit.com
Published: Jul 07 2008 / 10:35

Groovy has an interesting shortening of the ternary operator that it rather fancifully titles “the Elvis Operator“. This operator is hardly unique to Groovy - C# has had it since 2.0 in the form of the Null Coalescing Operator - but that doesn’t mean that it is not a language feature worth learning from. Surprisingly (for a C-derivative language), Scala entirely lacks any sort of ternary operator. However, the language syntax is more than flexible enough to implement something similar without ever having to dip into the compiler.
  • 12
  • 0
  • 578
  • 166

Comments

Add your comment
User 202026 avatar

shemnon replied ago:

1 votes Vote down Vote up Reply

Getting the words 'Elvis' and 'impersonating' into a DZone article and actually having them be relevant instead of gratuitous deserves an up vote. Now if there was only some way to get Vegas involved...

User 107114 avatar

daniel replied ago:

0 votes Vote down Vote up Reply

LOL I hadn't thought of that. Now, *realizing* that the words 'Elvis' and 'impersonating' have alternative application outside of CompSci deserves an up-vote in and of itself. :-)

Add your comment


Html tags not supported. Reply is editable for 5 minutes. Use [code lang="java|ruby|sql|css|xml"][/code] to post code snippets.

Voters For This Link (12)



Voters Against This Link (0)