javassist是否允许在条件表达式中修改运算符? [英] Does javassist let modify an operator in a conditional expression?
问题描述
我需要知道是否可以使用以下代码和javassist来操纵代码,以将逻辑运算符>"替换为<".
这是我要操作其字节码的类:
公共类TryClass {公共无效foo(){int a = 0;如果(a> 5){System.out.println(我爱苹果");}别的{System.out.println(我讨厌苹果");}}}
在操作之后,该类的执行应打印:我爱苹果"代替:我讨厌苹果"
在字节码级别本身没有<
或>
,它是<例如,使用code> if_icmple 进行比较-这是一条实际的字节码指令.像这样的 javassist
应该能够做到这一点,它被称为 build-time字节码检测工具,网上有很多关于此的文章." with "<".
Here is the class whose bytecode I want to manipulate:
public class TryClass {
public void foo(){
int a =0;
if(a>5){
System.out.println("I love apples");
}
else{
System.out.println("I hate apples");
}
}
}
After the manipulation the execution of the class should print: "I love apples" instead of: "I hate apples"
there is no <
or >
at the byte code level per-se, it's if_icmple
for example used for comparison - meaning it's an actual byte code instruction. As such javassist
should be able to do it, it's called build-time byte-code instrumentation and there are quite a few article online about this.
Here is one for example
这篇关于javassist是否允许在条件表达式中修改运算符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!