private static Method findMethod(Object instance,String name,Class<?>... parameterTypes) throws NoSuchMethodException {
  for (Class<?> clazz=instance.getClass(); clazz != null; clazz=clazz.getSuperclass()) {
    try {
      Method method=clazz.getDeclaredMethod(name,parameterTypes);
      if (!method.isAccessible()) {
        method.setAccessible(true);
      }
      return method;
    }
 catch (    NoSuchMethodException e) {
    }
  }
  throw new NoSuchMethodException("Method " + name + " with parameters "+ Arrays.asList(parameterTypes)+ " not found in "+ instance.getClass());
}

private static Method findMethod ( Object instance , String name , Class < ? > ... parameterTypes ) throws NoSuchMethodException { for ( Class < ? > clazz = instance . getClass ( ) ; clazz != null ; clazz = clazz . getSuperclass ( ) ) { try { Method method = clazz . getDeclaredMethod ( name , parameterTypes ) ; if ( ! method . isAccessible ( ) ) { method . setAccessible ( true ) ; } return method ; } catch ( NoSuchMethodException e ) { } } throw new NoSuchMethodException ( "Method " + name + " with parameters " + Arrays . asList ( parameterTypes ) + " not found in " + instance . getClass ( ) ) ; }
locates a given method anywhere in the class inheritance hierarchy .
