gpt4 book ai didi

JAVA BCEL NEWARRAY getType 基本类型

转载 作者:太空宇宙 更新时间:2023-11-04 08:33:00 24 4
gpt4 key购买 nike

我如何在 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

ARRAY int[] 没有任何类型

最佳答案

我想我不太明白你的问题,但是这个怎么样:

if(instr.getClass().isArray()) return instr instanceof NEWARRAY[];
else return instr instanceof NEWARRAY;

关于JAVA BCEL NEWARRAY getType 基本类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7073622/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com