Author Login
Post Reply
Setya schrieb:
> Hi blackdrag,
>
> Thanks for quick response.
>
> I've tried your suggestions, but none of them works.
does not? hmm... should have.. do you use 1.5.6?
> 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;
ok, imagine you need to call a method or set a field/property on a class
in Groovy. To accomplish this, Groovy needs a MetaClass. Now, this
happens not only for code you see, but also for code you do not see...
for example to set fields in the constructor
This means when the first line of your code is executed in the
constructor you already need a MetaClass. Therefor you can not affect
the current meta class with ExpandoMetaClass.enableGlobally(); in the
constrcutor, beause the point where this would affect the meta class is
already passed.
bye blackdrag
---------------------------------------------------------------------
To unsubscribe from this list, please visit:
http://xircles.codehaus.org/manage_email