Class ReflectionUtils


  • public class ReflectionUtils
    extends Object
    Various utility functions to simplify reflection use cases.

    This is primarily meant to be used with "safe" classes such that there shouldn't be a need to use AccessController to do priviledged actions.

    • Constructor Detail

      • ReflectionUtils

        public ReflectionUtils()
    • Method Detail

      • invokeGetter

        public static Object invokeGetter​(Object instance,
                                          String methodName)
        Invokes a ‘getter’ method of the given name on the given instance.

        The method is assumed to be a basic getter with no parameters. If no method exists, or there is a problem invoking the method, null will be returned.

        Parameters:
        instance - The instance to invoke the method on.
        methodName - The method name, if it exists.
        Returns:
        The return value of the method call, or null.
      • isClassPresent

        public static boolean isClassPresent​(String className,
                                             Class context)
        Checks if a class is present on the classpath
        Parameters:
        className - The name of the class to check the presence of
        context - The method name, if it exists.
        Returns:
        The boolean value indicating the presence of the class