Ok, I understand it better now. Thanks for explaining. Please ignore my last mail. I think our last mails cross each other on the way.
rgds,
Roshan
On Sat, Aug 23, 2008 at 7:53 PM, Roshan Dawrani
<roshandawrani@gmail.com> wrote:
The bit that - the per-instance meta class is already set by the time we are in the constructor - was a little clear. I was not sure what effect was setting it to null having after modifying the metaclass (adding getNextI() to it). Does making it null make groovy set it again and this time using the just-modified meta-class?
rgds,
RoshanOn Sat, Aug 23, 2008 at 7:46 PM, Jochen Theodorou
<blackdrag@gmx.org> wrote:
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