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?
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...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With