| Author |
Groovy - Basic Question
|
Sri Yasasvi
Greenhorn
Joined: Nov 07, 2008
Posts: 27
|
posted

0
|
Hi All,
I am new to Groovy. I am running some basic examples while learning.
Could anyone of you tell me why the last print statement is printing true.
def noParam = { -> println "I'm executed"; return "no param"}
def oneParam = { out -> println "Executed with a ${out.class} parameter"; out << "one param"}
println noParam != "no param // Printing true
Thanks,
Yasasvi
|
 |
Sri Yasasvi
Greenhorn
Joined: Nov 07, 2008
Posts: 27
|
posted

0
|
Here is my undrestanding.
noParam is Closure. So the statement (println noParam != "no param") is returning true.
Then i changed the statement (println noParam.toString() != "no param") . But it is still returning true. Could you please explain this.
|
 |
Mohamed Sanaulla
Bartender
Joined: Sep 08, 2007
Posts: 2928
|
|
|
Unlike simple code blocks, closures have to be executed. Try invoking call() on the closure and assign the result to some variable
|
Mohamed Sanaulla | My Blog
|
 |
Sri Yasasvi
Greenhorn
Joined: Nov 07, 2008
Posts: 27
|
posted

0
|
Thank you so much Mohamed!!!
Now i understand clearly.....
|
 |
 |
|
|
subject: Groovy - Basic Question
|
|
|