Class ReflectionUtil


  • public class ReflectionUtil
    extends Object
    • Constructor Detail

      • ReflectionUtil

        public ReflectionUtil()
    • Method Detail

      • invoke

        public static <T> T invoke​(Object target,
                                   String methodName,
                                   Object param1,
                                   Object param2,
                                   Object param3)
        Invoke a declared method with three parameters.
      • invoke

        public static <T> T invoke​(Object target,
                                   String methodName,
                                   Object param1,
                                   Object param2)
        Invoke a declared method with two parameters.
      • invoke

        public static <T> T invoke​(Object target,
                                   String methodName,
                                   Object param1)
        Invoke a declared method with one parameter.
      • invoke

        public static <T> T invoke​(Object target,
                                   String methodName)
        Invoke a declared method with no parameters
      • invokeStaticByArgs

        public static Object invokeStaticByArgs​(Class<?> klass,
                                                String methodName,
                                                Object... args)
      • getFieldValue

        public static <T> T getFieldValue​(Object o,
                                          String field)
      • getFieldValue

        public static <T> T getFieldValue​(Class<?> orig,
                                          String field)
      • setFieldValue

        public static void setFieldValue​(Object instance,
                                         String field,
                                         Object value)
      • setFieldValue

        public static void setFieldValue​(Object instance,
                                         Class<?> klass,
                                         String field,
                                         Object value)
      • setFieldValueOrFail

        public static void setFieldValueOrFail​(Object instance,
                                               Class<?> klass,
                                               String field,
                                               Object value)
                                        throws Exception
        Parameters:
        instance - the instance
        klass - lowest class in hierarchy to look into, restriction is needed when otherwise you might detect the same field name from unknown subclasses and change this instead
        field - the field name
        value - the new value of the field
        Throws:
        Exception - if field not set
      • getDeclaredField

        public static Field getDeclaredField​(Class<?> klass,
                                             String name)
      • getDeclaredMethod

        public static Method getDeclaredMethod​(Class<?> klass,
                                               String method,
                                               Class<?>... paramTypes)
      • getDeclaredConstructor

        public static Constructor<?> getDeclaredConstructor​(Class<?> klass,
                                                            Class<?>... paramTypes)
      • copyDeclaredFields

        public static void copyDeclaredFields​(Class<?> klass,
                                              Object src,
                                              Object dest)