ClassWriter cw = new ClassWriter(...);
byte[] bytes = cw.toByteArray();
I would like to create new class instance from bytes
array. How do I do this? Is it possible at all?
ClassLoader.defineClass()
Reference:
This is possible, and you need to use Reflection in order to achieve this. The psuedo code is:
final Class clazz = loadIntoCurrentClassLoader(bytes); //I'm assuming you wrote this already using defineClass
final YourClass foo ;
try {
foo = (YourClass) clazz.newInstance();
}
catch (final Exception e) {
throw new RuntimeException(e);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With