Code Snippets, Ideas and Rants from a Tech Lead interested primarily in server side web development and leading teams who build web apps.
Wednesday, November 3, 2010
Elvis Operator
Is really neat and not used enough. Basically it is a modified ternary.
Here is and example for returning a sensible value if an expressions resolves to null (or false).
def a = b ?: "No Value"
In that example a should equal b unless b is null or false, then it would be assigned "No Value"
No comments:
Post a Comment