Groovy console for beginner and meta programming

This assumes that you have setup groovy as per Setting up Groovy and groovysh beginner for eval exp, dynamic typing, operator overloading & closure.

Step 1: Start the groovyConsole from a command prompt

Step 2: Run the following Groovy Plain Old Object code

Execute it as a Groovy script.

Groovy console

Groovy console

Groovy meta programming with Expando class

The groovy.util.Expando class in Groovy is sort of a dynamic bean, which can add properties and closures as behavior at runtime. Groovy is a dynamic programming language, and the meta programming is the one that gives this dynamic behavior to change code at run time.

Here is the Expando class in action:


Groovy meta programming

Groovy meta programming

Groovy meta programming with ExpandoMetaClass

Every groovy class file including the final classes have a “metaClass” property. This property refers to groovy.lang.ExpandoMetaClass.

Groovy ExpandoMetaClass

Groovy ExpandoMetaClass

Java Interview FAQs

800+ Java Interview Q&As