Search code examples
javaclasson-the-fly

Adding new functionality to an application using on-the-fly class generation


Is it possible to generate subclasses at runtime or while an application is running? If so, how is this achieved and what precautions should be taken to prevent a rogue object wreaking havoc inside an application?

Edit: Title modified from "Class generation on the fly".


Solution

  • Take a look at Reflection API.

    Create Dynamic class "on the fly"

    Read this one too:

    Java Reflection: Create an implementing class - Jon Skeet answered it! :)