Answering my own question: It can be done if the metaClass is an ExpandoMetaClass. Like this:
expandoMetaClass.registerInstanceMethod( new TransformMetaMethod(originalMetaMethod) { @Override Object invoke(Object object, Object[] arguments) { println "Done! Method overriden!" super.invoke(object, arguments) } } ) Anyway, in grails it didn't work (it kept calling the original method). Had to use an AST. Regards, Douglas Em qui, 23 de fev de 2017 às 16:12, Douglas Mendes <douglas.men...@gmail.com> escreveu: Hi. How can I properly override a method given a java.lang.reflect.Method and its respective MetaClass? I know that can be achieved by overriding the MetaClass's *invokeMethod *but I can't do that (even if I could, would like to avoid). Pseudocode: *void doAnOverride(MetaClass metaClass, Method method) {* * metaClass."${method.name <http://method.name>}" = { args ->* * println "done"* * }* *}* Thanks, Douglas