AccessibleObject.setAccessible(boolean flag)

本文详细介绍了Java反射机制中的AccessibleObject类及其核心方法setAccessible的作用。该方法用于控制反射对象是否绕过Java语言的访问控制检查,这对于理解如何利用反射进行更深层次的编程具有重要意义。

JDK API中的解释

AccessibleObject 类是 Field、Method 和 Constructor 对象的基类。它提供了将反射的对象标记为在使用时取消默认 Java 语言访问控制检查的能力。对于公共成员、默认(打包)访问成员、受保护成员和私有成员,在分别使用 Field、Method 或 Constructor 对象来设置或获得字段、调用方法,或者创建和初始化类的新实例的时候,会执行访问检查。
在反射对象中设置 accessible 标志允许具有足够特权的复杂应用程序(比如 Java Object Serialization 或其他持久性机制)以某种通常禁止使用的方式来操作对象。
setAccessible 
public void setAccessible(boolean flag) 
                   throws SecurityException 

将 accessible 标志设置为指示的布尔值,值为 true 则指示反射的对象在使用时应该取消 Java 语言访问检查,从而提高了性能。值为 false 则指示反射的对象应该实施 Java 语言访问检查。

 

所以setAccessible是启用和禁用访问安全检查的开关,并不是为true就能访问为false就不能访问!

 

转载于:https://www.cnblogs.com/bbsno1/p/3271341.html

[main] WARN net.openhft.posix.internal.PosixAPIHolder -- Unable to load JNRPosixAPI com.oracle.svm.core.jdk.UnsupportedFeatureError: Proxy class defined by interfaces [interface net.openhft.posix.internal.jnr.WinJNRPosixInterface, interface jnr.ffi.provider.LoadedLibrary] not found. Generating proxy classes at runtime is not supported. Proxy classes need to be defined at image build time by specifying the list of interfaces that they implement. To define proxy classes use -H:DynamicProxyConfigurationFiles=<comma-separated-config-files> and -H:DynamicProxyConfigurationResources=<comma-separated-config-resources> options. [main] WARN net.openhft.affinity.Affinity -- Windows JNA-based affinity not usable because it failed to load! Reason: com.oracle.svm.core.jdk.UnsupportedFeatureError: Proxy class defined by interfaces [interface net.openhft.affinity.impl.WindowsJNAAffinity$CLibrary] not found. Generating proxy classes at runtime is not supported. Proxy classes need to be defined at image build time by specifying the list of interfaces that they implement. To define proxy classes use -H:DynamicProxyConfigurationFiles=<comma-separated-config-files> and -H:DynamicProxyConfigurationResources=<comma-separated-config-resources> options. Exception in thread "main" java.lang.ExceptionInInitializerError Caused by: java.lang.NoSuchMethodException: no such method: java.lang.reflect.AccessibleObject.setAccessible0(boolean)boolean/invokeVirtual Caused by: java.lang.NoSuchMethodError: java.lang.reflect.AccessibleObject.setAccessible0(boolean) 根据你给的方式,我在graalvm编译后运行exe文件报错如上
最新发布
10-01
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值