Java Reflection Method Get from Object getMethodValue(Object target, String methodName)

Here you can find the source of getMethodValue(Object target, String methodName)

Description

get method value by name.

License

Open Source License

Parameter

Parameter Description
target Object
methodName method name

Exception

Parameter Description
Exception ex

Return

object

Declaration

public static Object getMethodValue(Object target, String methodName)
        throws NoSuchMethodException, IllegalAccessException, InvocationTargetException 

Method Source Code


//package com.java2s;
import java.lang.reflect.*;

public class Main {
    /**//from www . ja  v a  2  s. c om
     * get method value by name.
     *
     * @param target Object
     * @param methodName method name
     * @return object
     * @throws Exception ex
     */
    public static Object getMethodValue(Object target, String methodName)
            throws NoSuchMethodException, IllegalAccessException, InvocationTargetException {
        Method method = target.getClass().getDeclaredMethod(methodName);

        return method.invoke(target);
    }
}

Related

  1. getMethodsByStartsWithName(String name, Object o)
  2. getMethodsForObject(Object o2, String[] passedMethods)
  3. getMethodsIncludingHierarchy(Object comp, Class annotation)
  4. getMethodValue(Method method, Object instance)
  5. getMethodValue(Object base, Method method)
  6. getMethodVector(Object object)
  7. getMethodWithExactName(Class clazz, String name)
  8. getMethodWithPrefix(final Object o, final String fieldName, final String prefix)