Class MethodUtils


  • public class MethodUtils
    extends java.lang.Object
    This file is a collection of reflection utilities for dealing with methods and constructors.
    Author:
    Sanjiva Weerawarana, Joseph Kesselman
    • Constructor Summary

      Constructors 
      Constructor Description
      MethodUtils()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static java.lang.reflect.Constructor getConstructor​(java.lang.Class targetClass, java.lang.Class[] argTypes)
      Class.getConstructor() finds only the entry point (if any) _exactly_ matching the specified argument types.
      static java.lang.reflect.Method getMethod​(java.lang.Class target, java.lang.String methodName, java.lang.Class[] argTypes, boolean isStaticReference)  
      static java.lang.reflect.Method getMethod​(java.lang.Object target, java.lang.String methodName, java.lang.Class[] argTypes)
      Class.getMethod() finds only the entry point (if any) _exactly_ matching the specified argument types.
      • Methods inherited from class java.lang.Object

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

      • MethodUtils

        public MethodUtils()
    • Method Detail

      • getConstructor

        public static java.lang.reflect.Constructor getConstructor​(java.lang.Class targetClass,
                                                                   java.lang.Class[] argTypes)
                                                            throws java.lang.SecurityException,
                                                                   java.lang.NoSuchMethodException
        Class.getConstructor() finds only the entry point (if any) _exactly_ matching the specified argument types. Our implmentation can decide between several imperfect matches, using the same search algorithm as the Java compiler. Note that all constructors are static by definition, so isStaticReference is true.
        Throws:
        java.lang.NoSuchMethodException - if constructor not found.
        java.lang.SecurityException
      • getMethod

        public static java.lang.reflect.Method getMethod​(java.lang.Class target,
                                                         java.lang.String methodName,
                                                         java.lang.Class[] argTypes,
                                                         boolean isStaticReference)
                                                  throws java.lang.SecurityException,
                                                         java.lang.NoSuchMethodException
        Throws:
        java.lang.SecurityException
        java.lang.NoSuchMethodException
      • getMethod

        public static java.lang.reflect.Method getMethod​(java.lang.Object target,
                                                         java.lang.String methodName,
                                                         java.lang.Class[] argTypes)
                                                  throws java.lang.SecurityException,
                                                         java.lang.NoSuchMethodException
        Class.getMethod() finds only the entry point (if any) _exactly_ matching the specified argument types. Our implmentation can decide between several imperfect matches, using the same search algorithm as the Java compiler. This version emulates the compiler behavior by allowing lookup to be performed against either a class or an instance -- classname.foo() must be a static method call, instance.foo() can invoke either static or instance methods.
        Parameters:
        target - object on which call is to be made
        methodName - name of method I'm lookin' for
        argTypes - array of argument types of method
        Returns:
        the desired method
        Throws:
        java.lang.SecurityException - if security violation
        java.lang.NoSuchMethodException - if no such method