« Return to Thread: Adding method as GString expression to per-instance metaclass

Re: Adding method as GString expression to per-instance metaclass

by Roshan Dawrani :: Rate this Message:

Reply to Author | View in Thread

Hi,
The issue is with the lines
---------------------------------------------
def expando = new Expando();
expando.metaClass = emc;
---------------------------------------------

Since Expando is a fully dynamically expandable bean, the call "expando.metaClass = emc" defines a new property metaClass for Expando bean instead of replacing its metaClass with emc.

The way to replace the metaClass for Expando is by calling "expando.setMetaClass(emc);" and not "expando.metaClass = emc;"

If you replace the meta-class as "expando.setMetaClass(emc);", then the new method getTest() is visible through emc as you are defining and the call goes through as expected.

HTH.
Roshan

On Sun, Sep 7, 2008 at 12:06 AM, Setya <jsetya@...> wrote:

>Does expando.getTest() work?

No, it doesn't either.

Strangely, If I use GString literal all works as expected.

I also tried to print all the method attached to expando instance :

emc.expandoMethods.each
{
 println it;
}

And the method 'getTest' is there !!!.

Setya
--
View this message in context: http://www.nabble.com/Adding-method-as-GString-expression-to-per-instance-metaclass-tp19349186p19349736.html
Sent from the groovy - user mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe from this list, please visit:

   http://xircles.codehaus.org/manage_email



 « Return to Thread: Adding method as GString expression to per-instance metaclass