The closest thing you can get is with Java: instrumentation . Basically you write some Java classes that are given a series of bytes that define the class, quench around with byte code, and return an array of bytes of the modified class. You then pack these classes into a JAR file and instruct the JVM to use them either on the command line or by adding an attribute to the manifest file of the toolkit JAR file.
Of course, if you do this, you need to use some byte manipulation library, such as ASM .
EDIT . If the class you are interested in implements interfaces, you can take a look at dynamic proxy classes through java.lang.reflect.Proxy . This has the disadvantage that code snippets that you donβt write that do new ClassOfInterest() are not affected, but have the following advantages:
- Being a lot easier than changing the byte code of classes.
- You can dynamically choose that different proxy instances act as if they have a different superclass.
- You do not need to worry about any
SecurityManager issues.
source share