I'd like to create a subclass programatically. I guess I have few options - Javassist, CGLib, BCEL, or ASM.
The use case is that one app's internals are class-oriented, and extensions are class-based. Therefore I can't have a single class as a base for multiple extensions driven by externalized scripts.
Now - how would I do that? I've found examples with intercepting method calls, field access, initialization etc. But nothing about subclassing.
I'd like to end up with a class which:
- has a name which I want.
- is a (direct, at best) subclass of a given class
- copies the constructor(s) from the parent class (or calls
super(...)
) - eventually, I'd like to give it some annotations.
I know it's possible because various dynamic languages integrations, like GroovyClassLoader
, can do that.