Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/396.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
Java 如何使用BCEL更改静态字段的值?_Java_Bytecode_Bytecode Manipulation_Bcel - Fatal编程技术网

Java 如何使用BCEL更改静态字段的值?

Java 如何使用BCEL更改静态字段的值?,java,bytecode,bytecode-manipulation,bcel,Java,Bytecode,Bytecode Manipulation,Bcel,例如,我想使用BCEL重置静态字段 private static final int myValue = 1; 至myValue=2。使用另一个字节码库(如ASM)是不可能的。我问题中的代码:用于编辑静态数组。但后来我将其更改为编辑局部变量。 编辑静态变量的代码如下所示: InstructionList il = new InstructionList(); InstructionFactory f = new InstructionFactory(constantPoolGen); il.a

例如,我想使用BCEL重置静态字段

private static final int myValue = 1;
myValue=2
。使用另一个字节码库(如ASM)是不可能的。

我问题中的代码:用于编辑静态数组。但后来我将其更改为编辑局部变量。 编辑静态变量的代码如下所示:

InstructionList il = new InstructionList();
InstructionFactory f = new InstructionFactory(constantPoolGen);
il.append(f.createGetStatic("MyClassName","MyVariableName",Type.INT));
il.append(new PUSH(contantPoolGen, 2));
il.append(new ISTORE());

我使用的指令列表被注入了一个方法中,因此我不确定这是否适用于您。

查找ConstantValue属性