groovy-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From alessio <aless...@gmail.com>
Subject "External" closures, why?
Date Tue, 01 Dec 2015 16:18:59 GMT
Hi,

I have just started to dig into Groovy and have been mostly impressed
by what it offers, however when I had a look at handling database
calls (http://docs.groovy-lang.org/latest/html/api/groovy/sql/Sql.html)
I stumbled upon a rather weird syntax

  sql.eachRow('select * from PROJECT where name=:foo', [foo:'Gradle']) {
       // process row
   }

Usually I'd say this is a "regular" block scope but in this context it
was obviously a closure/function pointer/callback. It took me a while
to dig into this to find out that it can also be passed as second
argument to the method and was added in 2.2

  http://www.groovy-lang.org/semantics.html#_calling_a_method_accepting_a_sam_type_with_a_closure
  https://issues.apache.org/jira/browse/GROOVY-6188 (the JSR link does
not work anymore)

My question now is, why? Apparently pre-2.2 one had to cast the
closure to the appropriate type. But why making it possible to
actually define the closure outside of the respective call?

At least for me this is HIGHLY confusing.

Thanks

Mime
View raw message