Class ReflectionUtils

    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static java.lang.Class<?> getCallerClass()
      Get caller class
      static java.lang.Class<?> getCallerClass​(int invocationFrame)
      Get the caller class
      static java.lang.String getCallerClassName()
      Get Caller class
      static boolean isInaccessibleObjectException​(java.lang.Throwable failure)
      Determine whether the specified Throwable is java.lang.reflect.InaccessibleObjectException
      static boolean isSupportedSunReflectReflection()
      Is supported sun.reflect.Reflection or not
      static java.util.Map<java.lang.String,​java.lang.Object> readFieldsAsMap​(java.lang.Object object)
      Read fields value as Map
      static <T> java.util.List<T> toList​(java.lang.Object array)
      Convert Array object to List
      • Methods inherited from class java.lang.Object

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

      • SUN_REFLECT_REFLECTION_CLASS_NAME

        public static final java.lang.String SUN_REFLECT_REFLECTION_CLASS_NAME
        Sun JDK implementation class: full name of sun.reflect.Reflection
        See Also:
        Constant Field Values
      • INACCESSIBLE_OBJECT_EXCEPTION_CLASS_NAME

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

        @Nullable
        public static final java.lang.Class<? extends java.lang.Throwable> INACCESSIBLE_OBJECT_EXCEPTION_CLASS
        The class of java.lang.reflect.InaccessibleObjectException since JDK 9. It may be null if the JDK version is less than 9.
    • Method Detail

      • isSupportedSunReflectReflection

        public static boolean isSupportedSunReflectReflection()
        Is supported sun.reflect.Reflection or not
        Returns:
        true if supported
      • getCallerClassName

        @Nonnull
        public static java.lang.String getCallerClassName()
        Get Caller class
        Returns:
        Get the Class name that called the method
      • getCallerClass

        @Nonnull
        public static java.lang.Class<?> getCallerClass()
                                                 throws java.lang.IllegalStateException
        Get caller class

        For instance,

             package com.acme;
             import ...;
             class Foo {
                 public void bar(){
        
                 }
             }
         
        Returns:
        Get caller class
        Throws:
        java.lang.IllegalStateException - If the caller class cannot be found
      • getCallerClass

        public static java.lang.Class<?> getCallerClass​(int invocationFrame)
        Get the caller class
        Parameters:
        invocationFrame - The frame of method invocation
        Returns:
        null if not found
      • toList

        @Nonnull
        public static <T> java.util.List<T> toList​(java.lang.Object array)
                                            throws java.lang.IllegalArgumentException
        Convert Array object to List
        Parameters:
        array - array object
        Returns:
        List
        Throws:
        java.lang.IllegalArgumentException - if the object argument is not an array
      • readFieldsAsMap

        @Nonnull
        public static java.util.Map<java.lang.String,​java.lang.Object> readFieldsAsMap​(java.lang.Object object)
        Read fields value as Map
        Parameters:
        object - object to be read
        Returns:
        fields value as Map
      • isInaccessibleObjectException

        public static boolean isInaccessibleObjectException​(java.lang.Throwable failure)
        Determine whether the specified Throwable is java.lang.reflect.InaccessibleObjectException
        Parameters:
        failure - Throwable instance
        Returns:
        true if the specified Throwable is java.lang.reflect.InaccessibleObjectException