Class MethodUtils


  • public final class MethodUtils
    extends java.lang.Object
    Functions around Method.
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static java.lang.String describeMethod​(java.lang.reflect.Method method)
      Describes given method in following format: <class-name>.<method-name>, for instance Object.hashCode.
      static java.lang.reflect.Method getCurrentMethod()
      Returns the currently called Method.
      static java.lang.reflect.Method getMethodOnStack​(int level)
      Returns the Method on the stack of level.
      static java.lang.String toString​(java.lang.reflect.Method method)
      Returns the specified method as string which shows method name and parameter types in a way which more compact than Method.toString().
      • Methods inherited from class java.lang.Object

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

      • toString

        public static final java.lang.String toString​(java.lang.reflect.Method method)
        Returns the specified method as string which shows method name and parameter types in a way which more compact than Method.toString().
      • getCurrentMethod

        public static final java.lang.reflect.Method getCurrentMethod()
        Returns the currently called Method.

        Returns null if none could be found.

      • getMethodOnStack

        public static final java.lang.reflect.Method getMethodOnStack​(int level)
        Returns the Method on the stack of level.

        level=0 is this method itself, level=1 is the method that called it and so forth. This method internally uses Class.getDeclaredMethods() to retrieve the Method.

        IMPORTANT NOTE: You should carefully use this method in a class having more than one method with the same name. The internal idea used here ( new Throwable().getStackTrace()) only returns a method name and does not make any other consideration.

        See Also:
        StackTraceElement.getMethodName()
      • describeMethod

        public static final java.lang.String describeMethod​(java.lang.reflect.Method method)
        Describes given method in following format: <class-name>.<method-name>, for instance Object.hashCode.