Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/367.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
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 - Fatal编程技术网

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

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) {

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) {

        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();
    }

}