例如,我想使用 BCEL 重置静态字段
private static final int myValue = 1;
到myValue = 2
. 无法使用其他字节码库,例如 ASM。
例如,我想使用 BCEL 重置静态字段
private static final int myValue = 1;
到myValue = 2
. 无法使用其他字节码库,例如 ASM。
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..