Class ReflectUtils


  • public final class ReflectUtils
    extends java.lang.Object
    The type Reflect utils.
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static java.lang.reflect.Field getField​(java.lang.Class<?> beanClass, java.lang.String name)
      Get field.
      static java.lang.Object getFieldValue​(java.lang.Object obj, java.lang.reflect.Field field)
      Gets field value.
      static java.lang.Object getFieldValue​(java.lang.Object obj, java.lang.String fieldName)
      Get field value object.
      static java.lang.Object invokeMethod​(java.lang.Object object, java.lang.String method, java.lang.Object... args)
      Invoke method ignore exception.
      static java.lang.Object invokeMethod​(java.lang.Object object, java.lang.String method, java.util.function.Consumer<java.lang.ReflectiveOperationException> errorCallBack, java.lang.Object... args)
      Invoke method by class.
      static java.lang.Object invokeStaticMethod​(java.lang.Class<?> clazz, java.lang.String method)
      Invoke static method by class.
      static boolean isPrimitive​(java.lang.Class<?> cls)
      Verify the cls is Primitive.
      static boolean isPrimitives​(java.lang.Class<?> cls)
      Verify the cls is Primitives (Maybe array).
      static void setFieldValue​(java.lang.Object obj, java.lang.String fieldName, java.lang.Object value)
      Set object property values directly.
      • Methods inherited from class java.lang.Object

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

      • getField

        public static java.lang.reflect.Field getField​(java.lang.Class<?> beanClass,
                                                       java.lang.String name)
                                                throws java.lang.SecurityException
        Get field.
        Parameters:
        beanClass - the bean class
        name - the name
        Returns:
        the field
        Throws:
        java.lang.SecurityException - the security exception
      • getFieldValue

        public static java.lang.Object getFieldValue​(java.lang.Object obj,
                                                     java.lang.String fieldName)
        Get field value object.
        Parameters:
        obj - the obj
        fieldName - the field name
        Returns:
        the object
      • getFieldValue

        public static java.lang.Object getFieldValue​(java.lang.Object obj,
                                                     java.lang.reflect.Field field)
        Gets field value.
        Parameters:
        obj - the obj
        field - the field
        Returns:
        the field value
      • invokeStaticMethod

        public static java.lang.Object invokeStaticMethod​(java.lang.Class<?> clazz,
                                                          java.lang.String method)
        Invoke static method by class.
        Parameters:
        clazz - class type
        method - method
        Returns:
        Method object
      • invokeMethod

        public static java.lang.Object invokeMethod​(java.lang.Object object,
                                                    java.lang.String method,
                                                    java.util.function.Consumer<java.lang.ReflectiveOperationException> errorCallBack,
                                                    java.lang.Object... args)
        Invoke method by class.
        Parameters:
        object - object
        method - method
        args - params
        errorCallBack - callback when throw exception
        Returns:
        Method object
      • invokeMethod

        public static java.lang.Object invokeMethod​(java.lang.Object object,
                                                    java.lang.String method,
                                                    java.lang.Object... args)
        Invoke method ignore exception.
        Parameters:
        object - object
        method - method
        args - param
        Returns:
        Method object
      • setFieldValue

        public static void setFieldValue​(java.lang.Object obj,
                                         java.lang.String fieldName,
                                         java.lang.Object value)
        Set object property values directly.
        Parameters:
        obj - object
        fieldName - tje field name
        value - the field value
      • isPrimitives

        public static boolean isPrimitives​(java.lang.Class<?> cls)
        Verify the cls is Primitives (Maybe array).
        Parameters:
        cls - class
        Returns:
        boolean
      • isPrimitive

        public static boolean isPrimitive​(java.lang.Class<?> cls)
        Verify the cls is Primitive.
        Parameters:
        cls - class
        Returns:
        boolean