groovy variable function
Posted
by bsreekanth
on Stack Overflow
See other posts from Stack Overflow
or by bsreekanth
Published on 2010-04-25T18:23:00Z
Indexed on
2010/04/25
19:03 UTC
Read the original article
Hit count: 405
groovy
|dynamic-languages
I'm not even sure about how to title this qn. But, hope there is an easy way to do it in dynamic language like groovy.
say I have a class Service, where I delegate the business logic. the methods in it are
funA(), funB()... funX()
.
Now I have a controller class, where I call the service closure, which can be invoked like service.funA() . Now based on a variable (which can have values A, B ... X
), I need to cal the correct service closure. Basically to avoid writing lot of if conditional statements. Something like service."fun+var"()
would do. I'm not sure whether it is possible to substitute variable in closure (function)name. or any way by passing function (name) as a parameter...not sure
I think PHP has a similar feature http://php.net/manual/en/functions.variable-functions.php
thanks for any pointer..
© Stack Overflow or respective owner