i’m learning groovy and I have a question concerning its metaprogramming facilities. From what I understand every object in groovy implements the groovy.lang.GroovyObject interface (implicitly added by groovy compiler). The latter interface contains the method getMetaClass() so I can do the following:
class MyGroovyClass{
}
def myGroovyClass = new MyGroovyClass();
println myGroovyClass.metaClass.name
The thing that I don’t understand is how objects compiled by a java compiler like java.lang.String get the metaClass property. Is this property defined in the actually MetaClass object that gets associated with java classes through the MetaClassRegistry?
In addition to methods added through the meta-object protocol, Groovy also augments classes in the JDK with additional methods defined in the
groovy.runtime.DefaultGroovyMethodsclass.Listand other collections get methods likeeachandcollect. The same mechanism adds agetMetaClassmethod tojava.lang.Object.