I have a legacy (not modifiable :-() code, that have a static initializer block.
I would like to create a subclass – but without running the static block.
Is there any way doing this? For example: class.ForName method has a second argument which is responsibe for initializing the class – but sadly, it doesn’t work for me (probably means something else ..): http://docs.oracle.com/javase/6/docs/api/java/lang/Class.html#forName(java.lang.String, boolean, java.lang.ClassLoader)
UPDATE: the above mentioned class.forName does not trigget initialization – but asking for a newInstance does 🙁
Thanks,
krisy
You can always patch the old class with ASM. Generating a new class from the old bytecode by ignoring the clinit block should be easy.
Here is the before and after for the following class:
Before:
Output:
Test static
test value
After:
Output:
null