import javassist.bytecode.Bytecode;
import javassist.bytecode.ConstPool;
public class Coverage {
public static void main(String[] args) {
ConstPool cp = new ConstPool("Hello");
byte[] b = new byte[100];
Bytecode bc = new Bytecode(cp);
b = bc.get();
System.out.println("Bytecode start");
for(int i = 0 ; i < b.length ; i++)
{
System.out.println(b);
}
System.out.println("Bytecode end");
}
} bc.get()没有返回任何内容。我的目标是获取类的字节码。
发布于 2012-09-11 12:03:50
您的System.out.println(b);每次都会打印整个数组,您需要System.out.println(b[i]);,但我不认为它会起作用。试着..。
public static void main(String[] args) {
ClassPool pool = ClassPool.getDefault();
try {
CtClass cc = pool.get("java.lang.String");
byte[] bytes = cc.toBytecode();
System.out.println("Bytecode start");
for (Byte b : bytes) {
System.out.println(b);
}
System.out.println("Bytecode end");
} catch (NotFoundException e) {
e.printStackTrace();
} catch (CannotCompileException e) {
e.printStackTrace();
}
}发布于 2012-09-17 11:36:48
要编写代码覆盖率工具,请参考此BCEL教程。
https://stackoverflow.com/questions/12367326
复制相似问题