i like to use the ExpandoMetaClass to add properties and methods during runtime.
For testing purposes I wrote:
class Foo{
}
println Foo.metaClass
def a1 = new Foo();
println a1.metaClass.class
Foo.metaClass.expando = true;
println Foo.metaClass.class
def a2 = new Foo();
println a2.metaClass.class
a2.metaClass.test = "value"
println a2.test
println a2.metaClass.properties.name
Unfortunately "println a2.metaClass.properties.name" returns
["expando", "test", "class", "expando", "metaClass", "test"]
I think this is related to the getProperties method in ExpandoMetaClass:
public List getProperties() {
List propertyList = new ArrayList();
propertyList.addAll(expandoProperties.values());
propertyList.addAll(super.getProperties());
return propertyList;
}
At first it reads the properties form the local list and adds the properties for MetaClassImpl afterwards. Why are all expando properties are hold twice?