Tutorial by Examples

// long form String sayHello(String name){ "Hello, ${name ? name : 'stranger'}." } // elvis String sayHello(String name){ "Hello, ${name ?: 'stranger'}." } Notice that the "elvis" format omits the "true" term because the original comparison...
def results = [] (1..4).each{ def what = (it%2) ? 'odd' : 'even' results << what } assert results == ['odd', 'even', 'odd', 'even'] Here, the if-condition (in (parentheses)) is slightly more complex than just testing for existence/Groovy-Truth.

Page 1 of 1