Java Reflection Method Invoke invokeMethod(Object cls, String methodName, Class paramClass, String paramValue)

Here you can find the source of invokeMethod(Object cls, String methodName, Class paramClass, String paramValue)

Description

invoke Method

License

Open Source License

Declaration

private static void invokeMethod(Object cls, String methodName, Class<?> paramClass, String paramValue)
            throws Exception 

Method Source Code


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

import java.lang.reflect.Method;
import java.lang.reflect.InvocationTargetException;

public class Main {
    private static void invokeMethod(Object cls, String methodName, Class<?> paramClass, String paramValue)
            throws Exception {
        try {//  w  w  w . ja va2s . c o  m
            Method method = cls.getClass().getMethod(methodName, new Class[] { paramClass });
            method.invoke(cls, new Object[] { paramValue });
        } catch (InvocationTargetException e) {
            Throwable cause = e.getCause();
            if (cause instanceof RuntimeException) {
                throw (RuntimeException) cause;
            }
            throw e;
        }
    }
}

Related

  1. invokeMethod(Object bean, Method method, Object... param)
  2. invokeMethod(Object bean, Method method, Object[] args)
  3. invokeMethod(Object caller, Object classInstance, String className, String methodName, String parameterClasses[], Object[] parameters)
  4. invokeMethod(Object caller, String methodName, Object[] params)
  5. invokeMethod(Object classInstance, Method method, Object... args)
  6. invokeMethod(Object destination, String methodName, Object argument)
  7. invokeMethod(Object handle, String methodName, Class[] parameterClasses, Object... args)
  8. invokeMethod(Object handler, String strMethod, Class[] cls, Object... params)
  9. invokeMethod(Object instance, String methodName, Class expectedReturnType)