Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Groovy Closure generic return/parameters?

Tags:

grails

groovy

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?

like image 258
Samson Avatar asked May 13 '14 14:05

Samson


1 Answers

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...

like image 187
tim_yates Avatar answered Oct 11 '22 20:10

tim_yates