Here you can find the source of findFields(final Class> clazz, final Predicate
private static List<Field> findFields(final Class<?> clazz, final Predicate<Field> filter)
//package com.java2s; //License from project: Open Source License import javax.annotation.Nullable; import java.lang.reflect.Field; import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.function.Predicate; public class Main { private static List<Field> findFields(final Class<?> clazz, final Predicate<Field> filter) { final List<Field> fields = new ArrayList<>(); collectFields(clazz, filter, fields); fields.forEach(field -> field.setAccessible(true)); return fields; }// ww w . j av a2 s. c o m private static void collectFields(@Nullable final Class<?> clazz, final Predicate<Field> filter, final List<Field> output) { if (clazz == null) return; Arrays.stream(clazz.getDeclaredFields()).filter(filter).forEach(output::add); collectFields(clazz.getSuperclass(), filter, output); } }