Class MethodUtils


  • public class MethodUtils
    extends java.lang.Object
    Utility reflection methods.
    • Constructor Summary

      Constructors 
      Constructor Description
      MethodUtils()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static int clearCache()
      Clear the method cache.
      static java.lang.reflect.Method getAccessibleMethod​(java.lang.Class<?> clazz, java.lang.reflect.Method method)
      Return an accessible method (that is, one that can be invoked via reflection) that implements the specified Method.
      static java.lang.reflect.Method getAccessibleMethod​(java.lang.Class<?> clazz, java.lang.String methodName)
      Return an accessible method (that is, one that can be invoked via reflection) with given name and a single parameter.
      static java.lang.reflect.Method getAccessibleMethod​(java.lang.Class<?> clazz, java.lang.String methodName, java.lang.Class<?> paramType)
      Return an accessible method (that is, one that can be invoked via reflection) with given name and a single parameter.
      static java.lang.reflect.Method getAccessibleMethod​(java.lang.Class<?> clazz, java.lang.String methodName, java.lang.Class<?>[] paramTypes)
      Return an accessible method (that is, one that can be invoked via reflection) with given name and parameters.
      static java.lang.reflect.Method getAccessibleMethod​(java.lang.reflect.Method method)
      Return an accessible method (that is, one that can be invoked via reflection) that implements the specified Method.
      static java.lang.reflect.Method getMatchingAccessibleMethod​(java.lang.Class<?> clazz, java.lang.String methodName, java.lang.Class<?>[] paramTypes)
      Find an accessible method that matches the given name and has compatible parameters.
      static java.lang.reflect.Method getMatchingAccessibleMethod​(java.lang.Class<?> clazz, java.lang.String methodName, java.lang.Object[] args, java.lang.Class<?>[] paramTypes)
      Find an accessible method that matches the given name and has compatible parameters.
      static java.lang.Object invokeExactMethod​(java.lang.Object object, java.lang.String methodName, java.lang.Object arg)
      Invoke a method whose parameter type matches exactly the object type.
      static java.lang.Object invokeExactMethod​(java.lang.Object object, java.lang.String methodName, java.lang.Object[] args)
      Invoke a method whose parameter types match exactly the object types.
      static java.lang.Object invokeExactMethod​(java.lang.Object object, java.lang.String methodName, java.lang.Object[] args, java.lang.Class<?>[] paramTypes)
      Invoke a method whose parameter types match exactly the parameter types given.
      static java.lang.Object invokeExactStaticMethod​(java.lang.Class<?> objectClass, java.lang.String methodName)
      Invoke a static method that has no parameters.
      static java.lang.Object invokeExactStaticMethod​(java.lang.Class<?> objectClass, java.lang.String methodName, java.lang.Object arg)
      Invoke a static method whose parameter type matches exactly the object type.
      static java.lang.Object invokeExactStaticMethod​(java.lang.Class<?> objectClass, java.lang.String methodName, java.lang.Object[] args)
      Invoke a static method whose parameter types match exactly the object types.
      static java.lang.Object invokeExactStaticMethod​(java.lang.Class<?> objectClass, java.lang.String methodName, java.lang.Object[] args, java.lang.Class<?>[] paramTypes)
      Invoke a static method whose parameter types match exactly the parameter types given.
      static java.lang.Object invokeGetter​(java.lang.Object object, java.lang.String getterName)
      Gets an Object property from a bean.
      static java.lang.Object invokeGetter​(java.lang.Object object, java.lang.String getterName, java.lang.Object arg)
      Gets an Object property from a bean.
      static java.lang.Object invokeGetter​(java.lang.Object object, java.lang.String getterName, java.lang.Object[] args)
      Gets an Object property from a bean.
      static java.lang.Object invokeMethod​(java.lang.Object object, java.lang.String methodName)
      Invoke a named method whose parameter type matches the object type.
      static java.lang.Object invokeMethod​(java.lang.Object object, java.lang.String methodName, java.lang.Object arg)
      Invoke a named method whose parameter type matches the object type.
      static java.lang.Object invokeMethod​(java.lang.Object object, java.lang.String methodName, java.lang.Object[] args)
      Invoke a named method whose parameter type matches the object type.
      static java.lang.Object invokeMethod​(java.lang.Object object, java.lang.String methodName, java.lang.Object[] args, java.lang.Class<?>[] paramTypes)
      Invoke a named method whose parameter type matches the object type.
      static void invokeSetter​(java.lang.Object object, java.lang.String setterName, java.lang.Object arg)
      Sets the value of a bean property to an Object.
      static void invokeSetter​(java.lang.Object object, java.lang.String setterName, java.lang.Object[] args)
      Sets the value of a bean property to an Object.
      static java.lang.Object invokeStaticMethod​(java.lang.Class<?> objectClass, java.lang.String methodName)
      Invoke a named static method that has no parameters.
      static java.lang.Object invokeStaticMethod​(java.lang.Class<?> objectClass, java.lang.String methodName, java.lang.Object arg)
      Invoke a named static method whose parameter type matches the object type.
      static java.lang.Object invokeStaticMethod​(java.lang.Class<?> objectClass, java.lang.String methodName, java.lang.Object[] args)
      Invoke a named static method whose parameter type matches the object type.
      static java.lang.Object invokeStaticMethod​(java.lang.Class<?> objectClass, java.lang.String methodName, java.lang.Object[] args, java.lang.Class<?>[] paramTypes)
      Invoke a named static method whose parameter type matches the object type.
      • Methods inherited from class java.lang.Object

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

      • EMPTY_CLASS_PARAMETERS

        public static final java.lang.Class<?>[] EMPTY_CLASS_PARAMETERS
        An empty class array
      • EMPTY_OBJECT_ARRAY

        public static final java.lang.Object[] EMPTY_OBJECT_ARRAY
        An empty object array
      • NO_METHODS

        public static final java.lang.reflect.Method[] NO_METHODS
    • Constructor Detail

      • MethodUtils

        public MethodUtils()
    • Method Detail

      • invokeSetter

        public static void invokeSetter​(java.lang.Object object,
                                        java.lang.String setterName,
                                        java.lang.Object arg)
                                 throws java.lang.NoSuchMethodException,
                                        java.lang.IllegalAccessException,
                                        java.lang.reflect.InvocationTargetException
        Sets the value of a bean property to an Object.
        Parameters:
        object - the bean to change
        setterName - the property name or setter method name
        arg - use this argument
        Throws:
        java.lang.NoSuchMethodException - the no such method exception
        java.lang.IllegalAccessException - the illegal access exception
        java.lang.reflect.InvocationTargetException - the invocation target exception
      • invokeSetter

        public static void invokeSetter​(java.lang.Object object,
                                        java.lang.String setterName,
                                        java.lang.Object[] args)
                                 throws java.lang.NoSuchMethodException,
                                        java.lang.IllegalAccessException,
                                        java.lang.reflect.InvocationTargetException
        Sets the value of a bean property to an Object.
        Parameters:
        object - the bean to change
        setterName - the property name or setter method name
        args - use this arguments
        Throws:
        java.lang.NoSuchMethodException - the no such method exception
        java.lang.IllegalAccessException - the illegal access exception
        java.lang.reflect.InvocationTargetException - the invocation target exception
      • invokeGetter

        public static java.lang.Object invokeGetter​(java.lang.Object object,
                                                    java.lang.String getterName)
                                             throws java.lang.NoSuchMethodException,
                                                    java.lang.IllegalAccessException,
                                                    java.lang.reflect.InvocationTargetException
        Gets an Object property from a bean.
        Parameters:
        object - the bean
        getterName - the property name or getter method name
        Returns:
        the property value (as an Object)
        Throws:
        java.lang.NoSuchMethodException - the no such method exception
        java.lang.IllegalAccessException - the illegal access exception
        java.lang.reflect.InvocationTargetException - the invocation target exception
      • invokeGetter

        public static java.lang.Object invokeGetter​(java.lang.Object object,
                                                    java.lang.String getterName,
                                                    java.lang.Object arg)
                                             throws java.lang.NoSuchMethodException,
                                                    java.lang.IllegalAccessException,
                                                    java.lang.reflect.InvocationTargetException
        Gets an Object property from a bean.
        Parameters:
        object - the bean
        getterName - the property name or getter method name
        arg - use this argument
        Returns:
        the property value (as an Object)
        Throws:
        java.lang.NoSuchMethodException - the no such method exception
        java.lang.IllegalAccessException - the illegal access exception
        java.lang.reflect.InvocationTargetException - the invocation target exception
      • invokeGetter

        public static java.lang.Object invokeGetter​(java.lang.Object object,
                                                    java.lang.String getterName,
                                                    java.lang.Object[] args)
                                             throws java.lang.NoSuchMethodException,
                                                    java.lang.IllegalAccessException,
                                                    java.lang.reflect.InvocationTargetException
        Gets an Object property from a bean.
        Parameters:
        object - the bean
        getterName - the property name or getter method name
        args - use this arguments
        Returns:
        the property value (as an Object)
        Throws:
        java.lang.NoSuchMethodException - the no such method exception
        java.lang.IllegalAccessException - the illegal access exception
        java.lang.reflect.InvocationTargetException - the invocation target exception
      • invokeMethod

        public static java.lang.Object invokeMethod​(java.lang.Object object,
                                                    java.lang.String methodName)
                                             throws java.lang.NoSuchMethodException,
                                                    java.lang.IllegalAccessException,
                                                    java.lang.reflect.InvocationTargetException

        Invoke a named method whose parameter type matches the object type.

        Parameters:
        object - invoke method on this object
        methodName - get method with this name
        Returns:
        the value returned by the invoked method
        Throws:
        java.lang.NoSuchMethodException - if there is no such accessible method
        java.lang.reflect.InvocationTargetException - wraps an exception thrown by the method invoked
        java.lang.IllegalAccessException - if the requested method is not accessible
      • invokeMethod

        public static java.lang.Object invokeMethod​(java.lang.Object object,
                                                    java.lang.String methodName,
                                                    java.lang.Object arg)
                                             throws java.lang.NoSuchMethodException,
                                                    java.lang.IllegalAccessException,
                                                    java.lang.reflect.InvocationTargetException

        Invoke a named method whose parameter type matches the object type.

        The behaviour of this method is less deterministic than invokeExactMethod(). It loops through all methods with names that match and then executes the first it finds with compatible parameters.

        This method supports calls to methods taking primitive parameters via passing in wrapping classes. So, for example, a Boolean class would match a boolean primitive.

        This is a convenient wrapper for invokeMethod(Object object,String methodName,Object[] args).

        Parameters:
        object - invoke method on this object
        methodName - get method with this name
        arg - use this argument
        Returns:
        the value returned by the invoked method
        Throws:
        java.lang.NoSuchMethodException - if there is no such accessible method
        java.lang.reflect.InvocationTargetException - wraps an exception thrown by the method invoked
        java.lang.IllegalAccessException - if the requested method is not accessible via reflection
      • invokeMethod

        public static java.lang.Object invokeMethod​(java.lang.Object object,
                                                    java.lang.String methodName,
                                                    java.lang.Object[] args)
                                             throws java.lang.NoSuchMethodException,
                                                    java.lang.IllegalAccessException,
                                                    java.lang.reflect.InvocationTargetException

        Invoke a named method whose parameter type matches the object type.

        The behaviour of this method is less deterministic than invokeExactMethod(Object object,String methodName,Object[] args). It loops through all methods with names that match and then executes the first it finds with compatible parameters.

        This method supports calls to methods taking primitive parameters via passing in wrapping classes. So, for example, a Boolean class would match a boolean primitive.

        This is a convenient wrapper for invokeMethod(Object object,String methodName,Object[] args,Class[] paramTypes).

        Parameters:
        object - invoke method on this object
        methodName - get method with this name
        args - use these arguments - treat null as empty array
        Returns:
        the value returned by the invoked method
        Throws:
        java.lang.NoSuchMethodException - if there is no such accessible method
        java.lang.reflect.InvocationTargetException - wraps an exception thrown by the method invoked
        java.lang.IllegalAccessException - if the requested method is not accessible via reflection
      • invokeMethod

        public static java.lang.Object invokeMethod​(java.lang.Object object,
                                                    java.lang.String methodName,
                                                    java.lang.Object[] args,
                                                    java.lang.Class<?>[] paramTypes)
                                             throws java.lang.NoSuchMethodException,
                                                    java.lang.IllegalAccessException,
                                                    java.lang.reflect.InvocationTargetException

        Invoke a named method whose parameter type matches the object type.

        The behaviour of this method is less deterministic than invokeExactMethod(Object object,String methodName,Object[] args,Class[] paramTypes). It loops through all methods with names that match and then executes the first it finds with compatible parameters.

        This method supports calls to methods taking primitive parameters via passing in wrapping classes. So, for example, a Boolean class would match a boolean primitive.

        Parameters:
        object - invoke method on this object
        methodName - get method with this name
        args - use these arguments - treat null as empty array
        paramTypes - match these parameters - treat null as empty array
        Returns:
        the value returned by the invoked method
        Throws:
        java.lang.NoSuchMethodException - if there is no such accessible method
        java.lang.reflect.InvocationTargetException - wraps an exception thrown by the method invoked
        java.lang.IllegalAccessException - if the requested method is not accessible via reflection
      • invokeExactMethod

        public static java.lang.Object invokeExactMethod​(java.lang.Object object,
                                                         java.lang.String methodName,
                                                         java.lang.Object arg)
                                                  throws java.lang.NoSuchMethodException,
                                                         java.lang.IllegalAccessException,
                                                         java.lang.reflect.InvocationTargetException

        Invoke a method whose parameter type matches exactly the object type.

        This is a convenient wrapper for invokeExactMethod(Object object,String methodName,Object[] args).

        Parameters:
        object - invoke method on this object
        methodName - get method with this name
        arg - use this argument
        Returns:
        the value returned by the invoked method
        Throws:
        java.lang.NoSuchMethodException - if there is no such accessible method
        java.lang.reflect.InvocationTargetException - wraps an exception thrown by the method invoked
        java.lang.IllegalAccessException - if the requested method is not accessible via reflection
      • invokeExactMethod

        public static java.lang.Object invokeExactMethod​(java.lang.Object object,
                                                         java.lang.String methodName,
                                                         java.lang.Object[] args)
                                                  throws java.lang.NoSuchMethodException,
                                                         java.lang.IllegalAccessException,
                                                         java.lang.reflect.InvocationTargetException

        Invoke a method whose parameter types match exactly the object types.

        This uses reflection to invoke the method obtained from a call to getAccessibleMethod().

        Parameters:
        object - invoke method on this object
        methodName - get method with this name
        args - use these arguments - treat null as empty array
        Returns:
        the value returned by the invoked method
        Throws:
        java.lang.NoSuchMethodException - if there is no such accessible method
        java.lang.reflect.InvocationTargetException - wraps an exception thrown by the method invoked
        java.lang.IllegalAccessException - if the requested method is not accessible via reflection
      • invokeExactMethod

        public static java.lang.Object invokeExactMethod​(java.lang.Object object,
                                                         java.lang.String methodName,
                                                         java.lang.Object[] args,
                                                         java.lang.Class<?>[] paramTypes)
                                                  throws java.lang.NoSuchMethodException,
                                                         java.lang.IllegalAccessException,
                                                         java.lang.reflect.InvocationTargetException

        Invoke a method whose parameter types match exactly the parameter types given.

        This uses reflection to invoke the method obtained from a call to getAccessibleMethod().

        Parameters:
        object - invoke method on this object
        methodName - get method with this name
        args - use these arguments - treat null as empty array
        paramTypes - match these parameters - treat null as empty array
        Returns:
        the value returned by the invoked method
        Throws:
        java.lang.NoSuchMethodException - if there is no such accessible method
        java.lang.reflect.InvocationTargetException - wraps an exception thrown by the method invoked
        java.lang.IllegalAccessException - if the requested method is not accessible via reflection
      • invokeExactStaticMethod

        public static java.lang.Object invokeExactStaticMethod​(java.lang.Class<?> objectClass,
                                                               java.lang.String methodName,
                                                               java.lang.Object[] args,
                                                               java.lang.Class<?>[] paramTypes)
                                                        throws java.lang.NoSuchMethodException,
                                                               java.lang.IllegalAccessException,
                                                               java.lang.reflect.InvocationTargetException

        Invoke a static method whose parameter types match exactly the parameter types given.

        This uses reflection to invoke the method obtained from a call to getAccessibleMethod(Class, String, Class[]).

        Parameters:
        objectClass - invoke static method on this class
        methodName - get method with this name
        args - use these arguments - treat null as empty array
        paramTypes - match these parameters - treat null as empty array
        Returns:
        the value returned by the invoked method
        Throws:
        java.lang.NoSuchMethodException - if there is no such accessible method
        java.lang.reflect.InvocationTargetException - wraps an exception thrown by the method invoked
        java.lang.IllegalAccessException - if the requested method is not accessible via reflection
      • invokeStaticMethod

        public static java.lang.Object invokeStaticMethod​(java.lang.Class<?> objectClass,
                                                          java.lang.String methodName)
                                                   throws java.lang.NoSuchMethodException,
                                                          java.lang.IllegalAccessException,
                                                          java.lang.reflect.InvocationTargetException
        Invoke a named static method that has no parameters.
        Parameters:
        objectClass - invoke static method on this class
        methodName - get method with this name
        Returns:
        the value returned by the invoked method
        Throws:
        java.lang.NoSuchMethodException - if there is no such accessible method
        java.lang.reflect.InvocationTargetException - wraps an exception thrown by the method invoked
        java.lang.IllegalAccessException - if the requested method is not accessible via reflection
      • invokeStaticMethod

        public static java.lang.Object invokeStaticMethod​(java.lang.Class<?> objectClass,
                                                          java.lang.String methodName,
                                                          java.lang.Object arg)
                                                   throws java.lang.NoSuchMethodException,
                                                          java.lang.IllegalAccessException,
                                                          java.lang.reflect.InvocationTargetException

        Invoke a named static method whose parameter type matches the object type.

        The behaviour of this method is less deterministic than invokeExactMethod(Object, String, Object[], Class[]). It loops through all methods with names that match and then executes the first it finds with compatible parameters.

        This method supports calls to methods taking primitive parameters via passing in wrapping classes. So, for example, a Boolean class would match a boolean primitive.

        This is a convenient wrapper for invokeStaticMethod(Class objectClass,String methodName,Object[] args).

        Parameters:
        objectClass - invoke static method on this class
        methodName - get method with this name
        arg - use this argument
        Returns:
        the value returned by the invoked method
        Throws:
        java.lang.NoSuchMethodException - if there is no such accessible method
        java.lang.reflect.InvocationTargetException - wraps an exception thrown by the method invoked
        java.lang.IllegalAccessException - if the requested method is not accessible via reflection
      • invokeStaticMethod

        public static java.lang.Object invokeStaticMethod​(java.lang.Class<?> objectClass,
                                                          java.lang.String methodName,
                                                          java.lang.Object[] args)
                                                   throws java.lang.NoSuchMethodException,
                                                          java.lang.IllegalAccessException,
                                                          java.lang.reflect.InvocationTargetException

        Invoke a named static method whose parameter type matches the object type.

        The behaviour of this method is less deterministic than invokeExactMethod(Object object,String methodName,Object[] args). It loops through all methods with names that match and then executes the first it finds with compatible parameters.

        This method supports calls to methods taking primitive parameters via passing in wrapping classes. So, for example, a Boolean class would match a boolean primitive.

        This is a convenient wrapper for invokeStaticMethod(Class objectClass,String methodName,Object[] args,Class[] paramTypes).

        Parameters:
        objectClass - invoke static method on this class
        methodName - get method with this name
        args - use these arguments - treat null as empty array
        Returns:
        the value returned by the invoked method
        Throws:
        java.lang.NoSuchMethodException - if there is no such accessible method
        java.lang.reflect.InvocationTargetException - wraps an exception thrown by the method invoked
        java.lang.IllegalAccessException - if the requested method is not accessible via reflection
      • invokeStaticMethod

        public static java.lang.Object invokeStaticMethod​(java.lang.Class<?> objectClass,
                                                          java.lang.String methodName,
                                                          java.lang.Object[] args,
                                                          java.lang.Class<?>[] paramTypes)
                                                   throws java.lang.NoSuchMethodException,
                                                          java.lang.IllegalAccessException,
                                                          java.lang.reflect.InvocationTargetException

        Invoke a named static method whose parameter type matches the object type.

        The behaviour of this method is less deterministic than invokeExactStaticMethod(Class objectClass,String methodName,Object[] args,Class[] paramTypes). It loops through all methods with names that match and then executes the first it finds with compatible parameters.

        This method supports calls to methods taking primitive parameters via passing in wrapping classes. So, for example, a Boolean class would match a boolean primitive.

        Parameters:
        objectClass - invoke static method on this class
        methodName - get method with this name
        args - use these arguments - treat null as empty array
        paramTypes - match these parameters - treat null as empty array
        Returns:
        the value returned by the invoked method
        Throws:
        java.lang.NoSuchMethodException - if there is no such accessible method
        java.lang.reflect.InvocationTargetException - wraps an exception thrown by the method invoked
        java.lang.IllegalAccessException - if the requested method is not accessible via reflection
      • invokeExactStaticMethod

        public static java.lang.Object invokeExactStaticMethod​(java.lang.Class<?> objectClass,
                                                               java.lang.String methodName)
                                                        throws java.lang.NoSuchMethodException,
                                                               java.lang.IllegalAccessException,
                                                               java.lang.reflect.InvocationTargetException
        Invoke a static method that has no parameters.
        Parameters:
        objectClass - invoke static method on this class
        methodName - get method with this name
        Returns:
        the value returned by the invoked method
        Throws:
        java.lang.NoSuchMethodException - if there is no such accessible method
        java.lang.reflect.InvocationTargetException - wraps an exception thrown by the method invoked
        java.lang.IllegalAccessException - if the requested method is not accessible via reflection
      • invokeExactStaticMethod

        public static java.lang.Object invokeExactStaticMethod​(java.lang.Class<?> objectClass,
                                                               java.lang.String methodName,
                                                               java.lang.Object arg)
                                                        throws java.lang.NoSuchMethodException,
                                                               java.lang.IllegalAccessException,
                                                               java.lang.reflect.InvocationTargetException
        Invoke a static method whose parameter type matches exactly the object type.

        This is a convenient wrapper for invokeExactStaticMethod(Class objectClass,String methodName,Object[] args).

        Parameters:
        objectClass - invoke static method on this class
        methodName - get method with this name
        arg - use this argument
        Returns:
        the value returned by the invoked method
        Throws:
        java.lang.NoSuchMethodException - if there is no such accessible method
        java.lang.reflect.InvocationTargetException - wraps an exception thrown by the method invoked
        java.lang.IllegalAccessException - if the requested method is not accessible via reflection
      • invokeExactStaticMethod

        public static java.lang.Object invokeExactStaticMethod​(java.lang.Class<?> objectClass,
                                                               java.lang.String methodName,
                                                               java.lang.Object[] args)
                                                        throws java.lang.NoSuchMethodException,
                                                               java.lang.IllegalAccessException,
                                                               java.lang.reflect.InvocationTargetException

        Invoke a static method whose parameter types match exactly the object types.

        This uses reflection to invoke the method obtained from a call to getAccessibleMethod(Class, String, Class[]).

        Parameters:
        objectClass - invoke static method on this class
        methodName - get method with this name
        args - use these arguments - treat null as empty array
        Returns:
        the value returned by the invoked method
        Throws:
        java.lang.NoSuchMethodException - if there is no such accessible method
        java.lang.reflect.InvocationTargetException - wraps an exception thrown by the method invoked
        java.lang.IllegalAccessException - if the requested method is not accessible via reflection
      • getAccessibleMethod

        public static java.lang.reflect.Method getAccessibleMethod​(java.lang.Class<?> clazz,
                                                                   java.lang.String methodName)

        Return an accessible method (that is, one that can be invoked via reflection) with given name and a single parameter. If no such method can be found, return null. Basically, a convenience wrapper that constructs a Class array for you.

        Parameters:
        clazz - get method from this class
        methodName - get method with this name
        Returns:
        the accessible method
      • getAccessibleMethod

        public static java.lang.reflect.Method getAccessibleMethod​(java.lang.Class<?> clazz,
                                                                   java.lang.String methodName,
                                                                   java.lang.Class<?> paramType)

        Return an accessible method (that is, one that can be invoked via reflection) with given name and a single parameter. If no such method can be found, return null. Basically, a convenience wrapper that constructs a Class array for you.

        Parameters:
        clazz - get method from this class
        methodName - get method with this name
        paramType - taking this type of parameter
        Returns:
        the accessible method
      • getAccessibleMethod

        public static java.lang.reflect.Method getAccessibleMethod​(java.lang.Class<?> clazz,
                                                                   java.lang.String methodName,
                                                                   java.lang.Class<?>[] paramTypes)

        Return an accessible method (that is, one that can be invoked via reflection) with given name and parameters. If no such method can be found, return null. This is just a convenient wrapper for getAccessibleMethod(Method method).

        Parameters:
        clazz - get method from this class
        methodName - get method with this name
        paramTypes - with these parameters types
        Returns:
        the accessible method
      • getAccessibleMethod

        public static java.lang.reflect.Method getAccessibleMethod​(java.lang.reflect.Method method)

        Return an accessible method (that is, one that can be invoked via reflection) that implements the specified Method. If no such method can be found, return null.

        Parameters:
        method - the method that we wish to call
        Returns:
        the accessible method
      • getAccessibleMethod

        public static java.lang.reflect.Method getAccessibleMethod​(java.lang.Class<?> clazz,
                                                                   java.lang.reflect.Method method)

        Return an accessible method (that is, one that can be invoked via reflection) that implements the specified Method. If no such method can be found, return null.

        Parameters:
        clazz - The class of the object
        method - The method that we wish to call
        Returns:
        the accessible method
      • getMatchingAccessibleMethod

        public static java.lang.reflect.Method getMatchingAccessibleMethod​(java.lang.Class<?> clazz,
                                                                           java.lang.String methodName,
                                                                           java.lang.Object[] args,
                                                                           java.lang.Class<?>[] paramTypes)

        Find an accessible method that matches the given name and has compatible parameters. Compatible parameters mean that every method parameter is assignable from the given parameters. In other words, it finds a method with the given name that will take the parameters given.

        This method is slightly undeterminstic since it loops through methods names and return the first matching method.

        This method is used by invokeMethod(Object object,String methodName,Object[] args,Class[] paramTypes).

        This method can match primitive parameter by passing in wrapper classes. For example, a Boolean will match a primitive boolean parameter.

        Parameters:
        clazz - find method in this class
        methodName - find method with this name
        args - find method with given arguments
        paramTypes - find method with compatible parameters
        Returns:
        the accessible method
      • getMatchingAccessibleMethod

        public static java.lang.reflect.Method getMatchingAccessibleMethod​(java.lang.Class<?> clazz,
                                                                           java.lang.String methodName,
                                                                           java.lang.Class<?>[] paramTypes)

        Find an accessible method that matches the given name and has compatible parameters. Compatible parameters mean that every method parameter is assignable from the given parameters. In other words, it finds a method with the given name that will take the parameters given.

        This method is slightly undeterminstic since it loops through methods names and return the first matching method.

        This method can match primitive parameter by passing in wrapper classes. For example, a Boolean will match a primitive boolean parameter.

        Parameters:
        clazz - find method in this class
        methodName - find method with this name
        paramTypes - find method with compatible parameters
        Returns:
        the accessible method
      • clearCache

        public static int clearCache()
        Clear the method cache.
        Returns:
        the number of cached methods cleared