类 ReflectionUtils

java.lang.Object
cn.taketoday.util.ReflectionUtils

public abstract class ReflectionUtils extends Object
Simple utility class for working with the reflection API and handling reflection exceptions.
从以下版本开始:
2.1.7
作者:
TODAY 2020-08-13 18:45
  • 字段详细资料

    • USER_DECLARED_METHODS

      public static final ReflectionUtils.MethodFilter USER_DECLARED_METHODS
      Pre-built MethodFilter that matches all non-bridge non-synthetic methods which are not declared on java.lang.Object.
    • COPYABLE_FIELDS

      public static final ReflectionUtils.FieldFilter COPYABLE_FIELDS
      Pre-built FieldFilter that matches all non-static, non-final fields.
    • CGLIB_RENAMED_METHOD_PREFIX

      public static final String CGLIB_RENAMED_METHOD_PREFIX
      Naming prefix for CGLIB-renamed methods.
      另请参阅:
    • EMPTY_FIELD_ARRAY

      private static final Field[] EMPTY_FIELD_ARRAY
    • EMPTY_METHOD_ARRAY

      private static final Method[] EMPTY_METHOD_ARRAY
    • EMPTY_OBJECT_ARRAY

      private static final Object[] EMPTY_OBJECT_ARRAY
    • DECLARED_FIELDS_CACHE

      private static final ConcurrentReferenceHashMap<Class<?>,Field[]> DECLARED_FIELDS_CACHE
      Cache for Class.getDeclaredFields(), allowing for fast iteration.
    • DECLARED_METHODS_CACHE

      private static final ConcurrentReferenceHashMap<Class<?>,Method[]> DECLARED_METHODS_CACHE
      Cache for Class.getDeclaredMethods() plus equivalent default methods from Java 8 based interfaces, allowing for fast iteration.
    • interfaceMethodCache

      private static final ConcurrentReferenceHashMap<Method,Method> interfaceMethodCache
      Cache for equivalent methods on an interface implemented by the declaring class.
      从以下版本开始:
      4.0
    • NON_OVERRIDABLE_MODIFIER

      private static final int NON_OVERRIDABLE_MODIFIER
      Precomputed value for the combination of private, static and final modifiers.
      另请参阅:
    • OVERRIDABLE_MODIFIER

      private static final int OVERRIDABLE_MODIFIER
      Precomputed value for the combination of public and protected modifiers.
      另请参阅:
  • 构造器详细资料

    • ReflectionUtils

      public ReflectionUtils()
  • 方法详细资料

    • handleReflectionException

      public static void handleReflectionException(Exception ex)
      Handle the given reflection exception.

      Should only be called if no checked exception is expected to be thrown by a target method, or if an error occurs while accessing a method or field.

      Throws the underlying RuntimeException or Error in case of an InvocationTargetException with such a root cause. Throws an IllegalStateException with an appropriate message or UndeclaredThrowableException otherwise.

      参数:
      ex - the reflection exception to handle
    • handleInvocationTargetException

      public static void handleInvocationTargetException(InvocationTargetException ex)
      Handle the given invocation target exception. Should only be called if no checked exception is expected to be thrown by the target method.

      Throws the underlying RuntimeException or Error in case of such a root cause. Throws an UndeclaredThrowableException otherwise.

      参数:
      ex - the invocation target exception to handle
    • rethrowRuntimeException

      public static void rethrowRuntimeException(Throwable ex)
      Rethrow the given exception, which is presumably the target exception of an InvocationTargetException. Should only be called if no checked exception is expected to be thrown by the target method.

      Rethrows the underlying exception cast to a RuntimeException or Error if appropriate; otherwise, throws an UndeclaredThrowableException.

      参数:
      ex - the exception to rethrow
      抛出:
      RuntimeException - the rethrown exception
    • rethrowException

      public static void rethrowException(Throwable ex) throws Exception
      Rethrow the given exception, which is presumably the target exception of an InvocationTargetException. Should only be called if no checked exception is expected to be thrown by the target method.

      Rethrows the underlying exception cast to an Exception or Error if appropriate; otherwise, throws an UndeclaredThrowableException.

      参数:
      ex - the exception to rethrow
      抛出:
      Exception - the rethrown exception (in case of a checked exception)
    • hasMethod

      public static boolean hasMethod(Class<?> clazz, String methodName, Class<?>... paramTypes)
      Determine whether the given class has a public method with the given signature.

      Essentially translates NoSuchMethodException to "false".

      参数:
      clazz - the clazz to analyze
      methodName - the name of the method
      paramTypes - the parameter types of the method
      返回:
      whether the class has a corresponding method
      从以下版本开始:
      4.0
      另请参阅:
    • getMethod

      public static Method getMethod(Class<?> clazz, String methodName, @Nullable Class<?>... paramTypes)
      Determine whether the given class has a public method with the given signature, and return it if available (else throws an IllegalStateException).

      In case of any signature specified, only returns the method if there is a unique candidate, i.e. a single public method with the specified name.

      Essentially translates NoSuchMethodException to IllegalStateException.

      参数:
      clazz - the clazz to analyze
      methodName - the name of the method
      paramTypes - the parameter types of the method (may be null to indicate any signature)
      返回:
      the method (never null)
      抛出:
      IllegalStateException - if the method has not been found
      从以下版本开始:
      4.0
      另请参阅:
    • getMethodIfAvailable

      @Nullable public static Method getMethodIfAvailable(Class<?> clazz, String methodName, @Nullable Class<?>... paramTypes)
      Determine whether the given class has a public method with the given signature, and return it if available (else return null).

      In case of any signature specified, only returns the method if there is a unique candidate, i.e. a single public method with the specified name.

      Essentially translates NoSuchMethodException to null.

      参数:
      clazz - the clazz to analyze
      methodName - the name of the method
      paramTypes - the parameter types of the method (may be null to indicate any signature)
      返回:
      the method, or null if not found
      从以下版本开始:
      4.0
      另请参阅:
    • getMethodCountForName

      public static int getMethodCountForName(Class<?> clazz, String methodName)
      Return the number of methods with a given name (with any argument types), for the given class and/or its superclasses. Includes non-public methods.
      参数:
      clazz - the clazz to check
      methodName - the name of the method
      返回:
      the number of methods with the given name
      从以下版本开始:
      4.0
    • getStaticMethod

      @Nullable public static Method getStaticMethod(Class<?> clazz, String methodName, Class<?>... args)
      Return a public static method of a class.
      参数:
      clazz - the class which defines the method
      methodName - the static method name
      args - the parameter types to the method
      返回:
      the static method, or null if no static method was found
      抛出:
      IllegalArgumentException - if the method name is blank or the clazz is null
    • getMethodOrNull

      @Nullable static Method getMethodOrNull(Class<?> clazz, String methodName, Class<?>[] paramTypes)
    • findMethodCandidatesByName

      private static Set<Method> findMethodCandidatesByName(Class<?> clazz, String methodName)
      从以下版本开始:
      4.0
    • hasMethod

      public static boolean hasMethod(Class<?> clazz, Method method)
      Determine whether the given class has a public method with the given signature.
      参数:
      clazz - the clazz to analyze
      method - the method to look for
      返回:
      whether the class has a corresponding method
      从以下版本开始:
      3.0
    • getMostSpecificMethod

      public static Method getMostSpecificMethod(Method method, @Nullable Class<?> targetClass)
      Given a method, which may come from an interface, and a target class used in the current reflective invocation, find the corresponding target method if there is one. E.g. the method may be IFoo.bar() and the target class may be DefaultFoo. In this case, the method may be DefaultFoo.bar(). This enables attributes on that method to be found.

      NOTE: In contrast to cn.taketoday.aop.support.AopUtils#getMostSpecificMethod, this method does not resolve Java 5 bridge methods automatically. Call BridgeMethodResolver.findBridgedMethod(java.lang.reflect.Method) if bridge method resolution is desirable (e.g. for obtaining metadata from the original method definition).

      参数:
      method - the method to be invoked, which may come from an interface
      targetClass - the target class for the current invocation (may be null or may not even implement the method)
      返回:
      the specific target method, or the original method if the targetClass does not implement it
      从以下版本开始:
      3.0
    • getInterfaceMethodIfPossible

      public static Method getInterfaceMethodIfPossible(Method method)
      Determine a corresponding interface method for the given method handle, if possible.

      This is particularly useful for arriving at a public exported type on Jigsaw which can be reflectively invoked without an illegal access warning.

      参数:
      method - the method to be invoked, potentially from an implementation class
      返回:
      the corresponding interface method, or the original method if none found
      从以下版本开始:
      4.0
      另请参阅:
    • getInterfaceMethodIfPossible

      public static Method getInterfaceMethodIfPossible(Method method, @Nullable Class<?> targetClass)
      Determine a corresponding interface method for the given method handle, if possible.

      This is particularly useful for arriving at a public exported type on Jigsaw which can be reflectively invoked without an illegal access warning.

      参数:
      method - the method to be invoked, potentially from an implementation class
      targetClass - the target class to check for declared interfaces
      返回:
      the corresponding interface method, or the original method if none found
      从以下版本开始:
      4.0
      另请参阅:
    • findInterfaceMethodIfPossible

      private static Method findInterfaceMethodIfPossible(Method method, Class<?> startClass, Class<?> endClass)
    • isOverridable

      private static boolean isOverridable(Method method, @Nullable Class<?> targetClass)
      Determine whether the given method is overridable in the given target class.
      参数:
      method - the method to check
      targetClass - the target class to check against
    • findMethod

      @Nullable public static Method findMethod(Class<?> clazz, String name)
      Attempt to find a Method on the supplied class with the supplied name and no parameters. Searches all superclasses up to Object.

      Returns null if no Method can be found.

      参数:
      clazz - the class to introspect
      name - the name of the method
      返回:
      the Method object, or null if none found
    • findMethod

      @Nullable public static Method findMethod(Class<?> clazz, String name, @Nullable Class<?>... paramTypes)
      Attempt to find a Method on the supplied class with the supplied name and parameter types. Searches all superclasses up to Object.

      Returns null if no Method can be found.

      参数:
      clazz - the class to introspect
      name - the name of the method
      paramTypes - the parameter types of the method (may be null to indicate any signature)
      返回:
      the Method object, or null if none found
    • hasSameParams

      private static boolean hasSameParams(Method method, Class<?>[] paramTypes)
    • findFunctionalInterfaceMethod

      public static Method findFunctionalInterfaceMethod(Class clazz)
      Find the method from FunctionalInterface
      抛出:
      IllegalArgumentException - if given class is not a FunctionalInterface
      从以下版本开始:
      4.0
      另请参阅:
    • invokeMethod

      @Nullable public static Object invokeMethod(Method method, @Nullable Object target)
      Invoke the specified Method against the supplied target object with no arguments. The target object can be null when invoking a static Method.

      Thrown exceptions are handled via a call to handleReflectionException(java.lang.Exception).

      参数:
      method - the method to invoke
      target - the target object to invoke the method on
      返回:
      the invocation result, if any
      另请参阅:
    • invokeMethod

      @Nullable public static Object invokeMethod(Method method, @Nullable Object target, Object... args)
      Invoke the specified Method against the supplied target object with the supplied arguments. The target object can be null when invoking a static Method.

      Thrown exceptions are handled via a call to handleReflectionException(java.lang.Exception).

      参数:
      method - the method to invoke
      target - the target object to invoke the method on
      args - the invocation arguments (may be null)
      返回:
      the invocation result, if any
    • declaresException

      public static boolean declaresException(Method method, Class<?> exceptionType)
      Determine whether the given method explicitly declares the given exception or one of its superclasses, which means that an exception of that type can be propagated as-is within a reflective invocation.
      参数:
      method - the declaring method
      exceptionType - the exception to throw
      返回:
      true if the exception can be thrown as-is; false if it needs to be wrapped
    • doWithLocalMethods

      public static void doWithLocalMethods(Class<?> clazz, ReflectionUtils.MethodCallback mc)
      Perform the given callback operation on all matching methods of the given class, as locally declared or equivalent thereof (such as default methods on Java 8 based interfaces that the given class implements).
      参数:
      clazz - the class to introspect
      mc - the callback to invoke for each method
      抛出:
      IllegalStateException - if introspection fails
      另请参阅:
    • doWithMethods

      public static void doWithMethods(Class<?> clazz, ReflectionUtils.MethodCallback mc)
      Perform the given callback operation on all matching methods of the given class and superclasses.

      The same named method occurring on subclass and superclass will appear twice, unless excluded by a ReflectionUtils.MethodFilter.

      参数:
      clazz - the class to introspect
      mc - the callback to invoke for each method
      抛出:
      IllegalStateException - if introspection fails
      另请参阅:
    • doWithMethods

      public static void doWithMethods(Class<?> clazz, ReflectionUtils.MethodCallback mc, @Nullable ReflectionUtils.MethodFilter mf)
      Perform the given callback operation on all matching methods of the given class and superclasses (or given interface and super-interfaces).

      The same named method occurring on subclass and superclass will appear twice, unless excluded by the specified ReflectionUtils.MethodFilter.

      参数:
      clazz - the class to introspect
      mc - the callback to invoke for each method
      mf - the filter that determines the methods to apply the callback to
      抛出:
      IllegalStateException - if introspection fails
    • getAllDeclaredMethods

      public static Method[] getAllDeclaredMethods(Class<?> leafClass)
      Get all declared methods on the leaf class and all superclasses. Leaf class methods are included first.
      参数:
      leafClass - the class to introspect
      抛出:
      IllegalStateException - if introspection fails
    • getDeclaredMethods

      public static Method[] getDeclaredMethods(Class<?> targetClass)
      Variant of Class.getDeclaredMethods() that uses a local cache in order to avoid the JVM's SecurityManager check and new Method instances. In addition, it also includes Java 8 default methods from locally implemented interfaces, since those are effectively to be treated just like declared methods.
      参数:
      targetClass - the class to introspect
      返回:
      the cached array of methods
      抛出:
      IllegalStateException - if introspection fails
      另请参阅:
    • getDeclaredMethods

      private static Method[] getDeclaredMethods(Class<?> targetClass, boolean defensive)
    • findDefaultMethodsOnInterfaces

      @Nullable private static List<Method> findDefaultMethodsOnInterfaces(Class<?> clazz)
    • getUniqueDeclaredMethods

      public static Method[] getUniqueDeclaredMethods(Class<?> leafClass)
      Get the unique set of declared methods on the leaf class and all superclasses. Leaf class methods are included first and while traversing the superclass hierarchy any methods found with signatures matching a method already included are filtered out.
      参数:
      leafClass - the class to introspect
      抛出:
      IllegalStateException - if introspection fails
    • getUniqueDeclaredMethods

      public static Method[] getUniqueDeclaredMethods(Class<?> leafClass, @Nullable ReflectionUtils.MethodFilter mf)
      Get the unique set of declared methods on the leaf class and all superclasses. Leaf class methods are included first and while traversing the superclass hierarchy any methods found with signatures matching a method already included are filtered out.
      参数:
      leafClass - the class to introspect
      mf - the filter that determines the methods to take into account
      抛出:
      IllegalStateException - if introspection fails
    • isEqualsMethod

      public static boolean isEqualsMethod(@Nullable Method method)
      Determine whether the given method is an "equals" method.
      另请参阅:
    • isHashCodeMethod

      public static boolean isHashCodeMethod(@Nullable Method method)
      Determine whether the given method is a "hashCode" method.
      另请参阅:
    • isToStringMethod

      public static boolean isToStringMethod(@Nullable Method method)
      Determine whether the given method is a "toString" method.
      另请参阅:
    • isObjectMethod

      public static boolean isObjectMethod(@Nullable Method method)
      Determine whether the given method is originally declared by Object.
    • isFinalizeMethod

      public static boolean isFinalizeMethod(@Nullable Method method)
      Determine whether the given method is a "finalize" method.
      另请参阅:
    • isCglibRenamedMethod

      public static boolean isCglibRenamedMethod(Method renamedMethod)
      Determine whether the given method is a CGLIB 'renamed' method, following the pattern "CGLIB$methodName$0".
      参数:
      renamedMethod - the method to check
    • makeAccessible

      public static Method makeAccessible(Method method)
      Make the given method accessible, explicitly setting it accessible if necessary. The setAccessible(true) method is only called when actually necessary, to avoid unnecessary conflicts with a JVM SecurityManager (if active).
      参数:
      method - the method to make accessible
      另请参阅:
    • toMethodArray

      public static Method[] toMethodArray(Collection<Method> collection)
      Copy the given Collection into a Method array.

      The Collection must contain Method elements only.

      参数:
      collection - the Collection to copy
      返回:
      the Method array
      从以下版本开始:
      4.0
      另请参阅:
    • findField

      @Nullable public static Field findField(Class<?> clazz, String name)
      Attempt to find a field on the supplied Class with the supplied name. Searches all superclasses up to Object.
      参数:
      clazz - the class to introspect
      name - the name of the field
      返回:
      the corresponding Field object, or null if not found
    • findField

      @Nullable public static Field findField(Class<?> clazz, @Nullable String name, @Nullable Class<?> type)
      Attempt to find a field on the supplied Class with the supplied name and/or type. Searches all superclasses up to Object.
      参数:
      clazz - the class to introspect
      name - the name of the field (may be null if type is specified)
      type - the type of the field (may be null if name is specified)
      返回:
      the corresponding Field object, or null if not found
    • findFieldIgnoreCase

      @Nullable public static Field findFieldIgnoreCase(Class<?> clazz, String name)
      Attempt to find a field on the supplied Class with the supplied name. Searches all superclasses up to Object.
      参数:
      clazz - the class to introspect
      name - the name of the field (with upper/lower case to be ignored)
      返回:
      the corresponding Field object, or null if not found
      从以下版本开始:
      4.0
    • setField

      public static void setField(Field field, Object target, @Nullable Object value)
      Set the field represented by the supplied field object on the specified target object to the specified value.

      In accordance with Field.set(Object, Object) semantics, the new value is automatically unwrapped if the underlying field has a primitive type.

      This method does not support setting static final fields.

      Thrown exceptions are handled via a call to handleReflectionException(Exception).

      参数:
      field - the field to set
      target - the target object on which to set the field
      value - the value to set (may be null)
    • getField

      @Nullable public static Object getField(Field field, @Nullable Object target)
      Get the field represented by the supplied field object on the specified target object. In accordance with Field.get(Object) semantics, the returned value is automatically wrapped if the underlying field has a primitive type.

      Thrown exceptions are handled via a call to handleReflectionException(Exception).

      参数:
      field - the field to get
      target - the target object from which to get the field
      返回:
      the field's current value
    • doWithLocalFields

      public static void doWithLocalFields(Class<?> clazz, ReflectionUtils.FieldCallback fc)
      Invoke the given callback on all locally declared fields in the given class.
      参数:
      clazz - the target class to analyze
      fc - the callback to invoke for each field
      抛出:
      IllegalStateException - if introspection fails
      另请参阅:
    • doWithFields

      public static void doWithFields(Class<?> clazz, ReflectionUtils.FieldCallback fc)
      Invoke the given callback on all fields in the target class, going up the class hierarchy to get all declared fields.
      参数:
      clazz - the target class to analyze
      fc - the callback to invoke for each field
      抛出:
      IllegalStateException - if introspection fails
    • doWithFields

      public static void doWithFields(Class<?> clazz, ReflectionUtils.FieldCallback fc, @Nullable ReflectionUtils.FieldFilter ff)
      Invoke the given callback on all fields in the target class, going up the class hierarchy to get all declared fields.
      参数:
      clazz - the target class to analyze
      fc - the callback to invoke for each field
      ff - the filter that determines the fields to apply the callback to
      抛出:
      IllegalStateException - if introspection fails
    • getDeclaredFields

      public static Field[] getDeclaredFields(Class<?> clazz)
      This variant retrieves Class.getDeclaredFields() from a local cache in order to avoid the JVM's SecurityManager check and defensive array copying.
      参数:
      clazz - the class to introspect
      返回:
      the cached array of fields
      抛出:
      IllegalStateException - if introspection fails
      另请参阅:
    • shallowCopyFieldState

      public static void shallowCopyFieldState(Object src, Object dest)
      Given the source object and the destination, which must be the same class or a subclass, copy all fields, including inherited fields. Designed to work on objects with public no-arg constructors.
      抛出:
      IllegalStateException - if introspection fails
    • copyField

      public static void copyField(Field field, Object src, Object dest)
      Copy a given field from the source object to the destination
      参数:
      field - target field property
    • makeAccessible

      public static Field makeAccessible(Field field)
      Make the given field accessible, explicitly setting it accessible if necessary. The setAccessible(true) method is only called when actually necessary, to avoid unnecessary conflicts with a JVM SecurityManager (if active).
      参数:
      field - the field to make accessible
      另请参阅:
    • isPublicStaticFinal

      public static boolean isPublicStaticFinal(Field field)
      Determine whether the given field is a "public static final" constant.
      参数:
      field - the field to check
    • toFieldArray

      public static Field[] toFieldArray(Collection<Field> fields)
      从以下版本开始:
      4.0
    • accessibleConstructor

      public static <T> Constructor<T> accessibleConstructor(Class<T> targetClass, Class<?>... parameterTypes)
      抛出:
      ConstructorNotFoundException - not found
      从以下版本开始:
      4.0
      另请参阅:
    • makeAccessible

      public static <T> Constructor<T> makeAccessible(Constructor<T> constructor)
    • hasConstructor

      public static boolean hasConstructor(Class<?> clazz, Class<?>... paramTypes)
      Determine whether the given class has a declared constructor with the given signature.

      Essentially translates NoSuchMethodException to "false".

      参数:
      clazz - the clazz to analyze
      paramTypes - the parameter types of the method
      返回:
      whether the class has a corresponding constructor
      从以下版本开始:
      4.0
      另请参阅:
    • getConstructorIfAvailable

      @Nullable public static <T> Constructor<T> getConstructorIfAvailable(Class<T> clazz, Class<?>... paramTypes)
      Determine whether the given class has a declared constructor with the given signature, and return it if available (else return null).

      Essentially translates NoSuchMethodException to null.

      参数:
      clazz - the clazz to analyze
      paramTypes - the parameter types of the method
      返回:
      the constructor, or null if not found
      从以下版本开始:
      4.0
      另请参阅:
    • getConstructor

      public static <T> Constructor<T> getConstructor(Class<T> type, Class<?>... parameterTypes)
      getDeclaredConstructor
      抛出:
      ConstructorNotFoundException - not found
      从以下版本开始:
      4.0
      另请参阅:
    • invokeConstructor

      public static <T> T invokeConstructor(Constructor<T> constructor, @Nullable Object[] args)
    • clearCache

      public static void clearCache()
      Clear the internal method/field cache.
    • obtainField

      public static Field obtainField(Class<?> clazz, String name)
    • obtainMethod

      public static Method obtainMethod(Class<?> targetClass, String methodName, Class<?>... parameterTypes)
    • findMethodWithMinimalParameters

      @Nullable public static Method findMethodWithMinimalParameters(Class<?> clazz, String methodName) throws IllegalArgumentException
      Find a method with the given method name and minimal parameters (best case: none), declared on the given class or one of its superclasses. Prefers public methods, but will return a protected, package access, or private method too.

      Checks Class.getMethods first, falling back to findDeclaredMethodWithMinimalParameters. This allows for finding public methods without issues even in environments with restricted Java security settings.

      参数:
      clazz - the class to check
      methodName - the name of the method to find
      返回:
      the Method object, or null if not found
      抛出:
      IllegalArgumentException - if methods of the given name were found but could not be resolved to a unique method with minimal parameters
      从以下版本开始:
      4.0
      另请参阅:
    • findDeclaredMethodWithMinimalParameters

      @Nullable public static Method findDeclaredMethodWithMinimalParameters(Class<?> clazz, String methodName) throws IllegalArgumentException
      Find a method with the given method name and minimal parameters (best case: none), declared on the given class or one of its superclasses. Will return a public, protected, package access, or private method.

      Checks Class.getDeclaredMethods, cascading upwards to all superclasses.

      参数:
      clazz - the class to check
      methodName - the name of the method to find
      返回:
      the Method object, or null if not found
      抛出:
      IllegalArgumentException - if methods of the given name were found but could not be resolved to a unique method with minimal parameters
      从以下版本开始:
      4.0
      另请参阅:
    • findMethodWithMinimalParameters

      @Nullable public static Method findMethodWithMinimalParameters(Method[] methods, String methodName) throws IllegalArgumentException
      Find a method with the given method name and minimal parameters (best case: none) in the given list of methods.
      参数:
      methods - the methods to check
      methodName - the name of the method to find
      返回:
      the Method object, or null if not found
      抛出:
      IllegalArgumentException - if methods of the given name were found but could not be resolved to a unique method with minimal parameters
      从以下版本开始:
      4.0
    • getReadMethod

      @Nullable public static Method getReadMethod(Field field)
      find getter method
      从以下版本开始:
      3.0.2
    • getReadMethod

      @Nullable public static Method getReadMethod(Class<?> declaredClass, @Nullable Class<?> type, String name)
      find getter method
      从以下版本开始:
      3.0.2
    • getWriteMethod

      @Nullable public static Method getWriteMethod(Field field)
      find setter method
      从以下版本开始:
      3.0.2
    • getWriteMethod

      @Nullable public static Method getWriteMethod(Class<?> declaredClass, @Nullable Class<?> type, String name)
      find setter method
      从以下版本开始:
      3.0.2
    • setterPropertyName

      static String setterPropertyName(String name, @Nullable Class<?> type)
         setterPropertyName("isName", boolean.class); -> setName
         setterPropertyName("isName", String.class); -> setIsName
       
    • getterPropertyName

      static String getterPropertyName(String name, @Nullable Class<?> type)
       getterPropertyName("isName", boolean.class); -> isName
       getterPropertyName("isName", String.class); -> getIsName
       
    • getPropertyName

      @Nullable public static String getPropertyName(@Nullable Method readMethod, @Nullable Method writeMethod)
      get property name from readMethod or writeMethod
      参数:
      readMethod - get method
      writeMethod - set method
      返回:
      property name
    • getParameterIndex

      public static int getParameterIndex(Parameter parameter)
      Get Parameter index
      参数:
      parameter - Parameter
      从以下版本开始:
      3.0
    • getParameter

      public static Parameter getParameter(Executable executable, int parameterIndex)
      Get Parameter with given parameterIndex
      参数:
      executable - Method or Constructor
      抛出:
      IllegalArgumentException - parameter index is illegal
      从以下版本开始:
      3.0
    • newInstance

      public static <T> T newInstance(String beanClassName) throws ClassNotFoundException
      Get instance with bean class
      参数:
      beanClassName - bean class name string
      返回:
      the instance of target class
      抛出:
      ClassNotFoundException - If the class was not found
      从以下版本开始:
      4.0
    • newInstance

      public static <T> T newInstance(Class<T> type)
      从以下版本开始:
      4.0
    • newInstance

      public static <T> T newInstance(Class<T> type, Class[] parameterTypes, @Nullable Object[] args)
      从以下版本开始:
      4.0
    • getProtectionDomain

      @Nullable public static ProtectionDomain getProtectionDomain(@Nullable Class<?> source)
      从以下版本开始:
      4.0