从类中获取所有声明的字段注意:getDeclaredFields()可能返回私有属性,但不返回Parents字段
//package com.nowjava; import java.lang.reflect.Field; /*来自 n o w j a v a . c o m*/ import java.util.Arrays; import java.util.List; public class Main { /** * Get all declared fields from Class<?> * Note : getDeclaredFields() may return private attributes, but does not return Parents fields * * @param fields * @param type * @return */ public static List<Field> getAllDeclaredFields(List<Field> fields, Class<?> type) { fields.addAll(Arrays.asList(type.getDeclaredFields())); if (type.getSuperclass() != null) { fields = getAllD