Wednesday, February 8, 2012

Copy method in Groovy

If you need to copy method reference between objects at runtime, it is super easy in Groovy. Just add & in front of method name and this it. For example:

new Expando(, user:it.user, mymethod:it.&othermethod, ...)

For some reason this is not very wide known feature (was not for me), and I unsuccessfully tried to use metaClass and other complicated things before finding this.

No comments:

Post a Comment