1

我如何在 BCEL 检查这个..

说java中的字节码是

newarray 10 (int)

我已经为访客完成了

instruction instanceof NEWARRAY

public boolean visit(Instruction instr) {
    return instr instanceof NEWARRAY;
}

但我还必须检查 newarray 是否是int[]

我如何在 BCEL 中检查这个?

我试过这个

 && ((NEWARRAY) instr).getType() == Type.INT;

return instr instanceof NEWARRAY && ((NEWARRAY) instr).getType() == Type.INT;

但是你可以看到上面的 ^ 不会起作用,因为它永远不会int......但是int[]

Type.INT只是int..而不是int[]..

我如何表示类型int[]

我正在阅读 BCEL 源代码,NEWARRAY.getType() 返回这个..

     /**
      * @return type of constructed array
      */
     public final Type getType() {
         return new ArrayType(BasicType.getType(type), 1);
     }

如您所见,它返回一个Type类,所以..查看 http://commons.apache.org/bcel/apidocs/org/apache/bcel/generic/Type.html

http://commons.apache.org/bcel/apidocs/org/apache/bcel/generic/ArrayType.html

TypeARRAY没有任何's int[]

4

1 回答 1

1

I don't think I understand your question well, but what about this:

if(instr.getClass().isArray()) return instr instanceof NEWARRAY[];
else return instr instanceof NEWARRAY;
于 2011-08-16T04:52:03.630 回答