Reputation: 107
I have a method that should take a Closure with first two parameters Car and Tyre and should return a type of Vehicle.
Is there a way to declare the type of parameters in Groovy Closures?
I am thinking
method(Closure<Vehicle, Car, Tyre> closure);
but what is the correct way?
Upvotes: 7
Views: 5156
Reputation: 171084
You can only define the return type of a Closure, ie: Closure<Vehicle>
As of Groovy 2.3, you can use @ClosureParam
to tweak the type system (see "Tweaking the type system" here), but Groovy 2.3 is not currently in Grails I believe...
Upvotes: 8
Reputation: 14529
The generic parameter on Closure is used for the return type. Closure<String>
shall return a string.
The parameters may be declared using the @ClosureParams
annotation
Upvotes: 0