public static <T>T invokeMethod(Object obj,String name,Object... params) throws NoSuchMethodException {
  Class[] paramTypes=getParamTypes(params);
  final Class<?> aClass=obj.getClass();
  Method method;
  try {
    method=aClass.getDeclaredMethod(name,paramTypes);
  }
 catch (  NoSuchMethodException e) {
    method=aClass.getMethod(name,paramTypes);
  }
  method.setAccessible(true);
  try {
    return (T)method.invoke(obj,params);
  }
 catch (  IllegalAccessException|InvocationTargetException e) {
    throw new RuntimeException(e);
  }
}

public static < T > T invokeMethod ( Object obj , String name , Object ... params ) throws NoSuchMethodException { Class [ ] paramTypes = getParamTypes ( params ) ; final Class < ? > aClass = obj . getClass ( ) ; Method method ; try { method = aClass . getDeclaredMethod ( name , paramTypes ) ; } catch ( NoSuchMethodException e ) { method = aClass . getMethod ( name , paramTypes ) ; } method . setAccessible ( true ) ; try { return ( T ) method . invoke ( obj , params ) ; } catch ( IllegalAccessException | InvocationTargetException e ) { throw new RuntimeException ( e ) ; } }
invokes a method by reflection .
