我想使用ASM将静态最终字段添加到.class文件中,源文件是
public class Example {
public Example(int code) {
this.code = code;
}
public int getCode() {
return code;
}
private final int code;
}
Run Code Online (Sandbox Code Playgroud)
并且生成的反编译类应该是这样的:
public class Example {
public static final Example FIRST = new Example(1);
public static final Example SECOND = new Example(2);
public Example(int code) {
this.code = code;
}
public int getCode() {
return code;
}
private final int code;
}
Run Code Online (Sandbox Code Playgroud)
作为结论,我想使用ASM将FIRST和SECOND常量添加到.class文件中,我该怎么办?
java assembly bytecode bytecode-manipulation java-bytecode-asm