summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorDivay Prakash <divayprakash@users.noreply.github.com>2019-08-30 21:36:36 +0530
committerGitHub <noreply@github.com>2019-08-30 21:36:36 +0530
commit4e8e92eb0eea94c87575776c2a0f3cea04296f6d (patch)
tree085b85c2845e08e25b306b8f919199f5dd4dc86f
parentf0f161981f2e3d35967878b6a7a2c71de75b2b64 (diff)
parentec1090d7a8758cb3759ba903b946594257e309f7 (diff)
Merge pull request #3614 from SMUsamaShah/patch-1
Optional parameters in methods
-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..89ca973a 100644
--- a/groovy.html.markdown
+++ b/groovy.html.markdown
@@ -181,6 +181,21 @@ class Foo {
}
/*
+ Methods with optional parameters
+*/
+
+// A mthod 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
*/