Java tutorial
//package com.java2s; //License from project: Open Source License import java.lang.reflect.Field; import java.util.Collections; import java.util.List; public class Main { /** * Extract all the fields of an object and its parent classes' fields iterative. * @param fields that belong to the class declaration. * @param type of the class from where extract the fields. * @return list of the fields fo the type class. */ private static List<Field> getAllFields(List<Field> fields, Class<?> type) { Collections.addAll(fields, type.getDeclaredFields()); if (type.getSuperclass() != null) { fields = getAllFields(fields, type.getSuperclass()); } return fields; } }