Java Reflection Method Invoke invokeMethod(java.lang.Object toObj, String tcMethodName, Class toResultClass)

Here you can find the source of invokeMethod(java.lang.Object toObj, String tcMethodName, Class toResultClass)

Description

invoke Method

License

Open Source License

Declaration

public static <T> T invokeMethod(java.lang.Object toObj, String tcMethodName, Class<T> toResultClass) 

Method Source Code

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

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

public class Main {
    public static <T> T invokeMethod(java.lang.Object toObj, String tcMethodName, Class<T> toResultClass) {
        try {/*w  w  w.j  av a 2 s  .  co m*/
            Method loMethod = toObj.getClass().getDeclaredMethod(tcMethodName);
            loMethod.setAccessible(true);
            return (T) loMethod.invoke(toObj);
        } catch (NoSuchMethodException ex) {
            throw new RuntimeException(ex);
        } catch (SecurityException ex) {
            throw new RuntimeException(ex);
        } catch (IllegalAccessException ex) {
            throw new RuntimeException(ex);
        } catch (InvocationTargetException ex) {
            throw new RuntimeException(ex);
        }
    }
}

Related

  1. invokeMethod(final Object obj, final Method method, final Object... args)
  2. invokeMethod(final Object obj, final String methodName, final boolean throwException)
  3. invokeMethod(final Object object, final String methodName, final Class[] parameterTypes, final Object[] parameters)
  4. invokeMethod(final Object object, final String methodName, final Class[] paramTypes, final Object[] parameters)
  5. invokeMethod(final Object p, final String methodName)
  6. invokeMethod(Method inMethod, Object inObject, Object[] inArgs)
  7. invokeMethod(Method m, Object instance, Object[] args)
  8. invokeMethod(Method m, Object[] o)
  9. invokeMethod(Method meth, String str)