Introduction to Groovy Meta-Object Protocol
This presentation will provide an introduction to Groovy meta-object programming. In the presentation, we'll examine various techniques for meta-programming in Groovy and take a deep dive into the method invocation flow through Groovy's MOP API. During the presentation, we'll see numerous demonstrations illustrating various MOP techniques. Time permitting, we'll explore a few ways Grails, the Groovy web application framework, leverages Groovy meta-programming.
Anyone who has programmed with Groovy is familiar with the many useful dynamic behaviors Groovy has seemingly added to Java classes. For instance, in Java we've always been able to do String concatenation with the + (plus) operator; i.e. “Hello” + World yields “Hello World”. With Groovy, java.lang.String now appears to have a bevy of new behaviors. For instance, with Groovy our Java String class now has the ability to subtract a substring from a String using the - (minus) operator; i.e. “Hello World” - " World” gives us “Hello”.
How the heck is that possible? Groovy seems to be messing with the Java String class that is tucked away safely in the Java runtime JAR. Is Groovy using some kind of runtime byte code manipulation or Java security hack to manipulate the String class?
Not at all. Groovy accomplishes this and most of its dynamic runtime tricks using the Groovy Meta-Object Protocol (MOP).
The presentation is intended for Java developers new to Groovy as well as experienced users of Groovy who want to do more than just consume the many predefined dynamic behaviors added by the Groovy JDK.