groovy-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Milles, Eric (TR Tech, Content & Ops)" <>
Subject Re: About polish the generics type syntax for closure
Date Wed, 13 Feb 2019 13:22:42 GMT
Why not use "public <V> V withSql(java.util.functional.Function<groovy.sql.Sql, V>
fn)" in this case?  @ClosureParams and @DelegatesTo are usable in Java code as well.  And
they cover a whole range of cases besides 1:1 mapping.  There are a number of SAM types that
can be used instead of Closure and you can also define your own.

From: Daniel Sun <>
Sent: Tuesday, February 12, 2019 7:46 PM
Subject: About polish the generics type syntax for closure

Hi all

       I've been developing a project with Groovy 3. When I try to specify
the generics type for closure, I have to use annotation..., which is quite
verbose... e.g.
public <V> V withSql(@ClosureParams(value= SimpleType.class,
options="groovy.sql.Sql") Closure<V> closure)

       I propose make the above code groovier, e.g.
public <V> V withSql(Closure<groovy.sql.Sql -> V> closure)

       Any thoughts?


Sent from:

View raw message