diff options
author | Dmitrii Kuznetsov <torgeek@gmail.com> | 2021-02-22 18:42:33 +0300 |
---|---|---|
committer | Dmitrii Kuznetsov <torgeek@gmail.com> | 2021-02-22 18:42:33 +0300 |
commit | e09fefaa3e78c645c720c86391e3f96d257be8a9 (patch) | |
tree | 0ff8b235e3e707125e2b11d5268ad085832355cb /groovy.html.markdown | |
parent | f4c740839d78f797e9cbcfa1eb0483ac0ea45501 (diff) | |
parent | bc8bd2646f068cfb402850f7c0f9b1dbfe81e5a0 (diff) |
Merge branch 'master' of https://github.com/torgeek/learnxinyminutes-docs
Diffstat (limited to 'groovy.html.markdown')
-rw-r--r-- | groovy.html.markdown | 19 |
1 files changed, 18 insertions, 1 deletions
diff --git a/groovy.html.markdown b/groovy.html.markdown index a3a45757..0d589c10 100644 --- a/groovy.html.markdown +++ b/groovy.html.markdown @@ -181,6 +181,21 @@ class Foo { } /* + Methods with optional parameters +*/ + +// A method can have default values for parameters +def say(msg = 'Hello', name = 'world') { + "$msg $name!" +} + +// It can be called in 3 different ways +assert 'Hello world!' == say() +// Right most parameter with default value is eliminated first. +assert 'Hi world!' == say('Hi') +assert 'learn groovy' == say('learn', 'groovy') + +/* Logical Branching and Looping */ @@ -230,10 +245,12 @@ for (i in array) { //Iterate over a map def map = ['name':'Roberto', 'framework':'Grails', 'language':'Groovy'] -x = 0 +x = "" for ( e in map ) { x += e.value + x += " " } +assert x.equals("Roberto Grails Groovy ") /* Operators |