在反射中,可以通过 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”
有什么线索吗?感谢捆绑,