mirror of
https://github.com/adambard/learnxinyminutes-docs.git
synced 2024-12-23 17:41:41 +00:00
Added The Elvis Operator to Groovy docs
This commit is contained in:
parent
a8621d1aad
commit
d810a71b76
@ -200,6 +200,14 @@ def y = 10
|
|||||||
def x = (y > 1) ? "worked" : "failed"
|
def x = (y > 1) ? "worked" : "failed"
|
||||||
assert x == "worked"
|
assert x == "worked"
|
||||||
|
|
||||||
|
//Groovy supports 'The Elvis Operator' too!
|
||||||
|
//Instead of using the ternary operator:
|
||||||
|
|
||||||
|
displayName = user.name ? user.name : 'Anonymous'
|
||||||
|
|
||||||
|
//We can write like this:
|
||||||
|
displayName = user.name ?: 'Anonymous'
|
||||||
|
|
||||||
//For loop
|
//For loop
|
||||||
//Iterate over a range
|
//Iterate over a range
|
||||||
def x = 0
|
def x = 0
|
||||||
@ -422,6 +430,3 @@ Join a [Groovy user group](http://www.groovy-lang.org/usergroups.html)
|
|||||||
[1] http://roshandawrani.wordpress.com/2010/10/18/groovy-new-feature-closures-can-now-memorize-their-results/
|
[1] http://roshandawrani.wordpress.com/2010/10/18/groovy-new-feature-closures-can-now-memorize-their-results/
|
||||||
[2] http://www.solutionsiq.com/resources/agileiq-blog/bid/72880/Programming-with-Groovy-Trampoline-and-Memoize
|
[2] http://www.solutionsiq.com/resources/agileiq-blog/bid/72880/Programming-with-Groovy-Trampoline-and-Memoize
|
||||||
[3] http://mrhaki.blogspot.mx/2011/05/groovy-goodness-cache-closure-results.html
|
[3] http://mrhaki.blogspot.mx/2011/05/groovy-goodness-cache-closure-results.html
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user