类 ReflectionUtils

    • 字段概要

      字段 
      修饰符和类型 字段 说明
      static java.lang.String SUN_REFLECT_REFLECTION_CLASS_NAME
      Sun JDK implementation class: full name of sun.reflect.Reflection
    • 方法概要

      所有方法 静态方法 具体方法 
      修饰符和类型 方法 说明
      static void assertArrayIndex​(java.lang.Object array, int index)
      Assert array index
      static void assertArrayType​(java.lang.Object array)
      Assert the object is array or not
      static void assertFieldMatchType​(java.lang.Object object, java.lang.String fieldName, java.lang.Class<?> expectedType)
      Assert Field type match
      static <T> java.util.Set<java.lang.Class<T>> findHierarchicalTypes​(java.lang.Class<?> sourceClass, java.lang.Class<T> matchType)
      Find the hierarchical types from the source class by specified type.
      static java.util.Set<java.lang.reflect.ParameterizedType> findParameterizedTypes​(java.lang.Class<?> sourceClass)
      Find the Set of ParameterizedType
      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 <T> T getProperty​(java.lang.Object bean, java.lang.String methodName)
      Get the value from the specified bean and its getter method.
      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 java.lang.Class[] resolveTypes​(java.lang.Object... values)
      Resolve the types of the specified values
      static <T> java.util.List<T> toList​(java.lang.Object array)
      Convert Array object to List
      • 从类继承的方法 java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • 字段详细资料

      • 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
        另请参阅:
        常量字段值
    • 构造器详细资料

      • ReflectionUtils

        public ReflectionUtils()
    • 方法详细资料

      • isSupportedSunReflectReflection

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

        @Nonnull
        public static java.lang.String getCallerClassName()
        Get Caller class
        返回:
        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(){
        
                 }
             }
         
        返回:
        Get caller class
        抛出:
        java.lang.IllegalStateException - If the caller class cannot be found
      • getCallerClass

        public static java.lang.Class<?> getCallerClass​(int invocationFrame)
        Get the caller class
        参数:
        invocationFrame - The frame of method invocation
        返回:
        null if not found
      • assertArrayIndex

        public static void assertArrayIndex​(java.lang.Object array,
                                            int index)
                                     throws java.lang.IllegalArgumentException
        Assert array index
        参数:
        array - Array object
        index - index
        抛出:
        java.lang.IllegalArgumentException - see assertArrayType(Object)
        java.lang.ArrayIndexOutOfBoundsException - If index is less than 0 or equals or greater than length of array
      • assertArrayType

        public static void assertArrayType​(java.lang.Object array)
                                    throws java.lang.IllegalArgumentException
        Assert the object is array or not
        参数:
        array - asserted object
        抛出:
        java.lang.IllegalArgumentException - if the object is not a array
      • assertFieldMatchType

        public static void assertFieldMatchType​(java.lang.Object object,
                                                java.lang.String fieldName,
                                                java.lang.Class<?> expectedType)
                                         throws java.lang.IllegalArgumentException
        Assert Field type match
        参数:
        object - Object
        fieldName - field name
        expectedType - expected type
        抛出:
        java.lang.IllegalArgumentException - if type is not matched
      • toList

        @Nonnull
        public static <T> java.util.List<T> toList​(java.lang.Object array)
                                            throws java.lang.IllegalArgumentException
        Convert Array object to List
        参数:
        array - array object
        返回:
        List
        抛出:
        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
        参数:
        object - object to be read
        返回:
        fields value as Map
      • findParameterizedTypes

        public static java.util.Set<java.lang.reflect.ParameterizedType> findParameterizedTypes​(java.lang.Class<?> sourceClass)
        Find the Set of ParameterizedType
        参数:
        sourceClass - the source class
        返回:
        non-null read-only Set
      • findHierarchicalTypes

        public static <T> java.util.Set<java.lang.Class<T>> findHierarchicalTypes​(java.lang.Class<?> sourceClass,
                                                                                  java.lang.Class<T> matchType)
        Find the hierarchical types from the source class by specified type.
        类型参数:
        T - the type to match
        参数:
        sourceClass - the source class
        matchType - the type to match
        返回:
        non-null read-only Set
      • getProperty

        public static <T> T getProperty​(java.lang.Object bean,
                                        java.lang.String methodName)
        Get the value from the specified bean and its getter method.
        类型参数:
        T - the type of property value
        参数:
        bean - the bean instance
        methodName - the name of getter
        返回:
      • resolveTypes

        public static java.lang.Class[] resolveTypes​(java.lang.Object... values)
        Resolve the types of the specified values
        参数:
        values - the values
        返回:
        If can't be resolved, return empty class array