Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
181 views
in Technique[技术] by (71.8m points)

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

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Here is a description how to implement an agent


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...