If you know Java, it's best to read how the metaclass is used in Groovy. Here is a decent explanation: http://skillsmatter.com/downloads/Groovy%20User%20Group%20December%202006.pdf
Just remember that everything in Groovy goes through metaClass. Apparently simple statements:
a = foo.bar bar = b foo.baz(1,2,3)
Translate roughly to this Java:
a = foo.getMetaClass().getProperty("bar"); this.getMetaClass().setProperty("bar",b); foo.getMetaClass().invokeMethod("baz",new Object[] {1,2,3});
Everything is sent via metaClass, since almost all Groovy functions work. The most important feature is probably closure . What you need to remember about closures is that it all tricks metaClass. The metaClass utility can be configured to try to call the / allow properties for your delegate, which basically means that you can do things like calling a method on an object that does not have this method.
source share