【发布时间】:2025-12-28 21:55:12
【问题描述】:
在反射中,可以通过 getDeclaredField() 和 setAccessible(true) 访问私有字段。如何通过 Objectweb ASM 字节码 API 访问外部类的私有字段? 我设置通过
之类的方式获取私有字段Field current = sourceObject.getDeclaredField(privateFieldName);
Field.setAccessible(true);
Type sourceType = Type.getType(sourceObject.getClass());
mv.visitFieldInsn(Opcodes.GETFIELD,
sourceType.getInternalName(),
privateFieldname,
Type.getDescriptor(current.getType()));
执行字节码获取私有字段时,总是报错“java.lang.IllegalAccessError”
有什么线索吗?谢谢你,
【问题讨论】:
标签: java reflection assembly bytecode java-bytecode-asm