diff options
author | Divay Prakash <divayprakash@users.noreply.github.com> | 2019-08-30 21:36:36 +0530 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-08-30 21:36:36 +0530 |
commit | 4e8e92eb0eea94c87575776c2a0f3cea04296f6d (patch) | |
tree | 085b85c2845e08e25b306b8f919199f5dd4dc86f | |
parent | f0f161981f2e3d35967878b6a7a2c71de75b2b64 (diff) | |
parent | ec1090d7a8758cb3759ba903b946594257e309f7 (diff) |
Merge pull request #3614 from SMUsamaShah/patch-1
Optional parameters in methods
-rw-r--r-- | groovy.html.markdown | 15 |
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 */ |