Extending or adding new classes at runtime in Java

Is there a way to add (or extend existing) classes at runtime in java. I am stuck with a problem in which I have to extend an existing class at runtime and add this to the classpath so that this new class is raised.

thanks,

+5
source share
3 answers

There are several ways to do this.

  • Compile the source code at runtime using the javax.tools package , and then load them using ClassLoader .
  • If you write on interfaces, you can decorate the proxy classes .
  • / - , BCEL ASM ( , ), ClassLoader.

, .

+11

BCEL. , , .

+4

, . , API .

0

All Articles