15.1 Creating Dynamic Classes with Expando
In Groovy we can create a class entirely at runtime. Suppose we’re building an application that will configure devices. We don’t have a clue what these devices are—we know only that devices have properties and configuration scripts. We don’t have the luxury of creating an explicit class for each device at coding time. So, we’ll want to synthesize classes at runtime to interact with and configure these devices. In Groovy, classes can come to life at runtime based on our command.
The Groovy Expando class gives us the ability to synthesize classes dynamically. It got its
name because it is dynamically expandable. We can assign properties and methods to it either at construction time using
a Map or ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access