@Nullable public static Method findNonPublicMethod(Class<?> cls,String name,Class<?>... paramTypes){
  while (cls != null) {
    try {
      Method mtd=cls.getDeclaredMethod(name,paramTypes);
      if (mtd.getReturnType() != void.class) {
        mtd.setAccessible(true);
        return mtd;
      }
    }
 catch (    NoSuchMethodException ignored) {
    }
    cls=cls.getSuperclass();
  }
  return null;
}

@ Nullable public static Method findNonPublicMethod ( Class < ? > cls , String name , Class < ? > ... paramTypes ) { while ( cls != null ) { try { Method mtd = cls . getDeclaredMethod ( name , paramTypes ) ; if ( mtd . getReturnType ( ) != void . class ) { mtd . setAccessible ( true ) ; return mtd ; } } catch ( NoSuchMethodException ignored ) { } cls = cls . getSuperclass ( ) ; } return null ; }
finds a method in the class and it parents . method . getmethod ( ) does not return non - public method , method . getdeclaratedmethod ( ) does not look at parent classes .
