Class ReflectionUtil


  • public class ReflectionUtil
    extends Object
    • Method Detail

      • hasMethods

        public static boolean hasMethods​(Object obj,
                                         String methodName)
      • getMethodNames

        public static Set<String> getMethodNames​(Object obj,
                                                 boolean includeInheritedMethods)
      • getMethodName

        protected static String getMethodName​(Method method)
      • discoverPublicClasses

        public static Class<?>[] discoverPublicClasses​(Class<?> clazz)
        Parameters:
        clazz -
        Returns:
        Since:
        1.6
      • getMethodsFromPublicClassesForName

        public static Method[] getMethodsFromPublicClassesForName​(Object obj,
                                                                  String methodName)
        Parameters:
        obj -
        methodName -
        Returns:
        Since:
        1.6
      • getMethodFor

        public static Method getMethodFor​(Object obj,
                                          String methodName,
                                          Object[] parameters,
                                          boolean includeInheritedMethods,
                                          boolean allowContravariantConversionForParameters)
        Parameters:
        allowContravariantConversionForParameters - when false, parameters will have exactly the same class as the arguments to the returned method when true, parameters may have a type that is more specific than the arguments to the returned method
      • getLegalMethod

        public static Method getLegalMethod​(Object obj,
                                            Method method)
        This tries to find a method such that invoking via reflection won't be illegal in Java 9+
        Parameters:
        obj -
        method -
        Returns:
        Since:
        1.6
      • methodToString

        public static String methodToString​(Method method)
        Returns a string representation of the method
        Parameters:
        method -
        Returns:
      • getFieldValue

        public static Object getFieldValue​(Object object,
                                           String fieldName)
        Returns the value of a field of an object
        Parameters:
        object -
        fieldName -
        Returns:
      • getField

        public static Field getField​(Class<?> clazz,
                                     String fieldName)
        Gets a field of a class using reflection by introspecting the class and its supertype(s)
        Parameters:
        clazz -
        fieldName -
        Returns:
      • isInstance

        public static boolean isInstance​(Class<?> clazz,
                                         Object instance)
        Checks if the instance is an instance of clazz Necessary because in Java, int.class != Integer.class etc
        Parameters:
        clazz -
        instance -
        Returns:
      • getAllInheritedInstanceFields

        public static List<Field> getAllInheritedInstanceFields​(Class<?> klazz)