Java: Is there a way to obtain the bytecode for a class at runtime?
Posted
by Adam Paynter
on Stack Overflow
See other posts from Stack Overflow
or by Adam Paynter
Published on 2010-04-29T12:36:10Z
Indexed on
2010/04/29
12:47 UTC
Read the original article
Hit count: 312
In Java, is there a way (at runtime) to obtain the bytecode which defined a particular class?
Put another way, is there a way to obtain the byte[] array passed to ClassLoader.defineClass(String name, byte[] b, int off, int len) when a particular class was loaded? I see that this method is declared final, so creating a custom ClassLoader to intercept class definitions seems out of the question.
In the past, I have used the class's ClassLoader to obtain the bytecode via the getResourceAsStream(String) method, but I would prefer a more canonical solution.
© Stack Overflow or respective owner