开发者

Is there a way to obtain the bytecode for a class at runtime?

开发者 https://www.devze.com 2022-12-29 03:03 出处:网络
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,

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 t开发者_C百科his 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.


Here is a description how to implement an agent


"Java agents" would be the obvious solution.

0

精彩评论

暂无评论...
验证码 换一张
取 消