Class AccessibleObjectUtils


  • public abstract class AccessibleObjectUtils
    extends BaseUtils
    The utilities class of AccessibleObject
    Since:
    1.0.0
    Author:
    Mercy
    See Also:
    AccessibleObject
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static boolean canAccess​(java.lang.Object object, java.lang.reflect.AccessibleObject accessibleObject)
      Test if the caller can access this reflected object.
      static boolean trySetAccessible​(java.lang.reflect.AccessibleObject accessibleObject)
      Try to set the AccessibleObject accessible.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • INACCESSIBLE_OBJECT_EXCEPTION_CLASS_NAME

        public static final java.lang.String INACCESSIBLE_OBJECT_EXCEPTION_CLASS_NAME
        The class name of java.lang.reflect.InaccessibleObject since JDK 9
        See Also:
        Constant Field Values
    • Constructor Detail

      • AccessibleObjectUtils

        public AccessibleObjectUtils()
    • Method Detail

      • trySetAccessible

        public static boolean trySetAccessible​(java.lang.reflect.AccessibleObject accessibleObject)
        Try to set the AccessibleObject accessible.

        If JDK >=9 , AccessibleObject#trySetAccessible() method will be invoked, or AccessibleObject.setAccessible(boolean) method will be invoked if AccessibleObject.isAccessible() is false.

        Parameters:
        accessibleObject - the AccessibleObject instance
        Returns:
        See Also:
        AccessibleObject#trySetAccessible(), AccessibleObject.setAccessible(boolean), AccessibleObject.isAccessible()
      • canAccess

        public static boolean canAccess​(java.lang.Object object,
                                        java.lang.reflect.AccessibleObject accessibleObject)
        Test if the caller can access this reflected object. If this reflected object corresponds to an instance method or field then this method tests if the caller can access the given obj with the reflected object. For instance methods or fields then the obj argument must be an instance of the declaring class. For static members and constructors then obj must be null.
        Parameters:
        object - an instance object of the declaring class of this reflected object if it is an instance method or field
        Returns:
        true if the caller can access this reflected object.