public static Field findField(TypeToken<?> classType, String fieldName,
                                Predicate<Field> predicate) throws NoSuchFieldException {
    for (Class<?> clz : classType.getTypes().classes().rawTypes()) {
      try {
        Field field = clz.getDeclaredField(fieldName);
        if (predicate.apply(field)) {
          return field;
        }
      } catch (NoSuchFieldException e) {
        // OK to ignore, keep finding.
      }
    }
    throw new NoSuchFieldException("Field " + fieldName + " not exists in the class hierarchy of " + classType);
  }
public static Field findField ( TypeToken < ? > classType , String fieldName , Predicate < Field > predicate ) throws NoSuchFieldException { for ( Class < ? > clz : classType . getTypes ( ) . classes ( ) . rawTypes ( ) ) { try { Field field = clz . getDeclaredField ( fieldName ) ; if ( predicate . apply ( field ) ) { return field ; } } catch ( NoSuchFieldException e ) { } } throw new NoSuchFieldException ( "Field " + fieldName + " not exists in the class hierarchy of " + classType ) ; }
Find a {@link java.lang.reflect.Field} in the class hierarchy of the given type that passes the predicate.
@param classType The leaf class to start with.
@param fieldName Name of the field.
@param predicate Predicate for accepting a matched field.
@return A {@link java.lang.reflect.Field} if found.
@throws NoSuchFieldException If the field is not found.