Reputation: 5552
In groovy you got closure which I kinda get, (similar to js, and ruby blocks) but I came across this code and I would like some clarification.
def bar = {
-1
}
..
..
.
getResults foo, bar , params, Foo.class.simpleName
Which get getResults is a method that takes a closure bar as a parameter. What I don't get is that in the method it has this:
public int getResults ( foo, bar , params, classSimpleName) {
def totalCount = bar(params)
..
..
.
Now bar(params) returns -1 which is the value of it. But I dont get how it works. is params a predefined word?
I am working in Grails and I know that my params passed to to controller, have no bar variable in them, and I dont know how they are related to this.
Upvotes: 0
Views: 211
Reputation: 3584
bar
is a closure. You are invoking the closure with params
parameter. bar
closure does not care about any parameters. It always returns -1
. That's it.
params
is a predefined variable in grails controllers.
Upvotes: 2