« Return to Thread: Method created via ExpandoMetaClass is not recognized

Re: Method created via ExpandoMetaClass is not recognized

by Setya :: Rate this Message:

Reply to Author | View in Thread

Hi blackdrag,

Thanks for quick response.

I've tried your suggestions, but none of them works.

Regarding ExpandoMetaClass.enableGlobally(), If I put it in MyGroovyClassImpl.groovy than the GroovyClassLoader won't parse the file as instance of MyJavaInterface. If I add it when evaluating the script, it doesn't take effect.

But If I put those scripts in 1 file it works as expected as follows:

class MyGroovyClassImpl
{
    MyGroovyClassImpl()
    {
        MyGroovyClassImpl.metaClass.getNext = {->println 'This is next command.';};
    }
}
ExpandoMetaClass.enableGlobally();
def context = new MyGroovyClassImpl();
context.next;

Regards,

Setya

 « Return to Thread: Method created via ExpandoMetaClass is not recognized