Skip to content

Instantly share code, notes, and snippets.

@Felk
Created September 15, 2017 13:54
Show Gist options
  • Save Felk/ed4375d27c755e21d0e6893847286d93 to your computer and use it in GitHub Desktop.
Save Felk/ed4375d27c755e21d0e6893847286d93 to your computer and use it in GitHub Desktop.
/** 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