例如,我想使用BCEL重置一个静态字段。
private static final int myValue = 1;敬myValue = 2。不可能使用其他字节码库(如ASM )。
发布于 2013-10-14 17:07:32
我问题中的代码:Injecting code in an existing method using BCEL用于编辑静态数组。不过,我后来将其更改为编辑局部变量。编辑静态变量的代码如下所示:
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());我用的InstructionList是用一种方法注射的,所以我不确定这对你是否有效。
https://stackoverflow.com/questions/18879277
复制相似问题