Module java.base

Class Method

    • Method Detail

      • setAccessible

        public void setAccessible​(boolean flag)
        Description copied from class: AccessibleObject
        Set the accessible flag for this reflected object to the indicated boolean value. A value of true indicates that the reflected object should suppress checks for Java language access control when it is used. A value of false indicates that the reflected object should enforce checks for Java language access control when it is used, with the variation noted in the class description.

        This method may be used by a caller in class C to enable access to a member of declaring class D if any of the following hold:

        • C and D are in the same module.
        • The member is public and D is public in a package that the module containing D exports to at least the module containing C.
        • The member is protected static, D is public in a package that the module containing D exports to at least the module containing C, and C is a subclass of D.
        • D is in a package that the module containing D opens to at least the module containing C. All packages in unnamed and open modules are open to all modules and so this method always succeeds when D is in an unnamed or open module.

        This method cannot be used to enable access to private members, members with default (package) access, protected instance members, or protected constructors when the declaring class is in a different module to the caller and the package containing the declaring class is not open to the caller's module.

        If there is a security manager, its checkPermission method is first called with a ReflectPermission("suppressAccessChecks") permission.

        Overrides:
        setAccessible in class AccessibleObject
        Parameters:
        flag - the new value for the accessible flag
        Throws:
        InaccessibleObjectException - if access cannot be enabled
        SecurityException - if the request is denied by the security manager
        See Also:
        AccessibleObject.trySetAccessible(), MethodHandles.privateLookupIn(java.lang.Class<?>, java.lang.invoke.MethodHandles.Lookup)
      • getDeclaringClass

        public Class<?> getDeclaringClass​()
        Returns the Class object representing the class or interface that declares the method represented by this object.
        Specified by: