Javassist:字节码.get()不工作 导入javassist.bytecode.bytecode; 导入javassist.bytecode.ConstPool; 公共课覆盖率{ 公共静态void main(字符串[]args){ ConstPool cp=新ConstPool(“你好”); 字节[]b=新字节[100]; 字节码bc=新字节码(cp); b=bc.get(); System.out.println(“字节码开始”); for(int i=0;i
bc.get()未返回任何内容。我的目标是得到一个类的字节码。那么你的Javassist:字节码.get()不工作 导入javassist.bytecode.bytecode; 导入javassist.bytecode.ConstPool; 公共课覆盖率{ 公共静态void main(字符串[]args){ ConstPool cp=新ConstPool(“你好”); 字节[]b=新字节[100]; 字节码bc=新字节码(cp); b=bc.get(); System.out.println(“字节码开始”); for(int i=0;i,java,javassist,bytecode-manipulation,Java,Javassist,Bytecode Manipulation,bc.get()未返回任何内容。我的目标是得到一个类的字节码。那么你的系统.out.println(b)每次都要打印整个数组,需要System.out.println(b[i])但我认为这无论如何都行不通。试试看 import javassist.bytecode.Bytecode; import javassist.bytecode.ConstPool; public class Coverage { public static void main(String[] args) {
系统.out.println(b)
每次都要打印整个数组,需要System.out.println(b[i])代码>但我认为这无论如何都行不通。试试看
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");
}
}
要编写代码覆盖率工具,请参阅此部分
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();
}
}