groovy-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Milles, Eric (TR Tech, Content & Ops)" <eric.mil...@thomsonreuters.com>
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 <realbluesun@hotmail.com>
Sent: Tuesday, February 12, 2019 7:46 PM
To: dev@groovy.incubator.apache.org
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?


Cheers,
Daniel.Sun



--
Sent from: https://urldefense.proofpoint.com/v2/url?u=http-3A__groovy.329449.n5.nabble.com_Groovy-2DDev-2Df372993.html&d=DwICAg&c=4ZIZThykDLcoWk-GVjSLmy8-1Cr1I4FWIvbLFebwKgY&r=tPJuIuL_GkTEazjQW7vvl7mNWVGXn3yJD5LGBHYYHww&m=DFJTyfeM1ifwZi7jWOJzHk2DUeAJqD75ON_ZAz6ArbQ&s=lS5nCK2jlmIDPsVhuCRmcbD4HEHI-hx5ZaBqznfDl34&e=

Mime
View raw message