Java tutorial
//package com.java2s; import java.lang.reflect.Field; import java.util.ArrayList; import java.util.Arrays; import java.util.List; public class Main { public static List<Field> getDeclaredFields(Class<?> cls) { List<Field> list = new ArrayList<>(); list.addAll(Arrays.asList(cls.getDeclaredFields())); if (!cls.getSuperclass().getName().equals(Object.class.getName())) { list.addAll(getDeclaredFields(cls.getSuperclass())); } return list; } }