Created
September 15, 2017 13:54
-
-
Save Felk/ed4375d27c755e21d0e6893847286d93 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** Usage: | |
* final BytecodeClassLoader classLoader = new BytecodeClassLoader(bytecode); | |
* final Class<?> newClass = classLoader.loadClass("com.example.SomeClass"); | |
*/ | |
public class BytecodeClassLoader extends ClassLoader { | |
private byte[] bytes; | |
public BytecodeClassLoader(byte[] bytes) { | |
super(); | |
this.bytes = bytes; | |
} | |
@Override | |
protected Class<?> findClass(String name) throws ClassNotFoundException { | |
return defineClass(name, bytes, 0, bytes.length); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment