From 9afd4fd1bd7ea9fb32dd3957c07380d3879da753 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kamil=20=C5=81opusza=C5=84ski?= Date: Wed, 4 Oct 2017 16:15:38 +0200 Subject: [groovy] small fix in iteration over a map --- groovy.html.markdown | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'groovy.html.markdown') diff --git a/groovy.html.markdown b/groovy.html.markdown index a3a45757..efbb2b32 100644 --- a/groovy.html.markdown +++ b/groovy.html.markdown @@ -230,10 +230,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 -- cgit v1.2.3 From ec1090d7a8758cb3759ba903b946594257e309f7 Mon Sep 17 00:00:00 2001 From: Muhammad Usama Date: Fri, 30 Aug 2019 19:58:06 +0500 Subject: Optional parameters in methods --- groovy.html.markdown | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'groovy.html.markdown') diff --git a/groovy.html.markdown b/groovy.html.markdown index efbb2b32..89ca973a 100644 --- a/groovy.html.markdown +++ b/groovy.html.markdown @@ -180,6 +180,21 @@ class Foo { def lastName } +/* + 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 */ -- cgit v1.2.3 From c23bbf004ae4f37f64a75c0942bf3340bcd83871 Mon Sep 17 00:00:00 2001 From: Michael Federczuk Date: Fri, 17 Apr 2020 15:52:38 +0200 Subject: Fix typo in groovy.html.markdown "mthod" -> "method" --- groovy.html.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'groovy.html.markdown') diff --git a/groovy.html.markdown b/groovy.html.markdown index 89ca973a..0d589c10 100644 --- a/groovy.html.markdown +++ b/groovy.html.markdown @@ -184,7 +184,7 @@ class Foo { Methods with optional parameters */ -// A mthod can have default values for parameters +// A method can have default values for parameters def say(msg = 'Hello', name = 'world') { "$msg $name!" } -- cgit v1.2.3