summaryrefslogtreecommitdiffhomepage
path: root/groovy.html.markdown
diff options
context:
space:
mode:
authorDimitris Kokkonis <kokkonisd@gmail.com>2020-10-10 12:31:09 +0200
committerDimitris Kokkonis <kokkonisd@gmail.com>2020-10-10 12:31:09 +0200
commit916dceba25fcca6d7d9858d25c409bc9984c5fce (patch)
treefb9e604256d3c3267e0f55de39e0fa3b4b0b0728 /groovy.html.markdown
parent922fc494bcce6cb53d80a5c2c9c039a480c82c1f (diff)
parent33cd1f57ef49f4ed0817e906b7579fcf33c253a1 (diff)
Merge remote-tracking branch 'upstream/master' into master
Diffstat (limited to 'groovy.html.markdown')
-rw-r--r--groovy.html.markdown15
1 files changed, 15 insertions, 0 deletions
diff --git a/groovy.html.markdown b/groovy.html.markdown
index efbb2b32..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
*/