JAVA BCEL NEWARRAY getType 基本类型
我如何在 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
没有任何 Type
对于数组int[]
。
How do I in BCEL check for this..
Say the bytecode in java is
newarray 10 (int)
I got this already done for visitor
instruction instanceof NEWARRAY
public boolean visit(Instruction instr) {
return instr instanceof NEWARRAY;
}
But I also have to check if the newarray is int[]
how do I check this in BCEL?
I tried this
&& ((NEWARRAY) instr).getType() == Type.INT;
to well
return instr instanceof NEWARRAY && ((NEWARRAY) instr).getType() == Type.INT;
But you can see the above ^ will not work as it will never be int
.. but int[]
But Type.INT
is just int
.. and not int[]
..
How I represent Type int[]
?
I was reading the BCEL source code and NEWARRAY.getType() returns this..
/**
* @return type of constructed array
*/
public final Type getType() {
return new ArrayType(BasicType.getType(type), 1);
}
As you can see it returns a Type
class so.. looking at
http://commons.apache.org/bcel/apidocs/org/apache/bcel/generic/Type.html
http://commons.apache.org/bcel/apidocs/org/apache/bcel/generic/ArrayType.html
there isn't any Type
's for ARRAY int[]
.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我想我不太明白你的问题,但是这个怎么样:
I don't think I understand your question well, but what about this: