0

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

private static final int myValue = 1;

myValue = 2. 无法使用其他字节码库,例如 ASM。

4

1 回答 1

1

The code in my question: Injecting code in an existing method using BCEL used to edit a static array. I however later changed it to edit a local variable. The code to edit a static variable was something like this:

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());

The InstructionList I used got injected in a method so i'm not sure if that works for you..

于 2013-10-14T17:07:32.770 回答