Java Reflection Method Invoke invokeMethod(Object target, String thisMethod, Object value)

Here you can find the source of invokeMethod(Object target, String thisMethod, Object value)

Description

Invokes the specified method

License

Open Source License

Parameter

Parameter Description
target The new param value
value The new param value
thisMethod Description of the Parameter

Return

Description of the Returned Value

Declaration

public static boolean invokeMethod(Object target, String thisMethod, Object value) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.lang.reflect.Method;

public class Main {
    /**//from   w ww  .  j av  a  2  s . c o  m
     *  Invokes the specified method
     *
     * @param  target      The new param value
     * @param  value       The new param value
     * @param  thisMethod  Description of the Parameter
     * @return             Description of the Returned Value
     */
    public static boolean invokeMethod(Object target, String thisMethod, Object value) {
        try {
            if (value != null) {
                Class[] argTypes = new Class[] { value.getClass() };
                Method method = target.getClass().getMethod(thisMethod, argTypes);
                method.invoke(target, new Object[] { value });
            }
        } catch (Exception e) {
            //e.printStackTrace(System.out);
            if (System.getProperty("DEBUG") != null) {
                System.out.println("ObjectUtils-> invokeMethod Exception");
            }
            return false;
        }
        return true;
    }
}

Related

  1. invokeMethod(Object target, String methodName, Object... parameters)
  2. invokeMethod(Object target, String methodName, Object[] arguments)
  3. invokeMethod(Object target, String name, Class... parameterTypes)
  4. invokeMethod(Object target, String name, Object[] args, Class[] argTypes)
  5. invokeMethod(Object target, String signature, Object... args)
  6. invokeMethod(Object theObject, String methodName, Object... parametersObject)
  7. invokeMethod(String className, String method, Class[] paramTypes, Object obj, Object[] args)
  8. invokeMethod(String methodName, Object gameCommand)
  9. invokeMethod(String name, Object target)