Here you can find the source of invokeMethod(java.lang.Object toObj, String tcMethodName, Class
public static <T> T invokeMethod(java.lang.Object toObj, String tcMethodName, Class<T> toResultClass)
//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); } } }