检索常量字段
/**N o w J a v a . c o m**/ //package com.nowjava; import java.lang.reflect.Field; import java.lang.reflect.Modifier; import java.util.ArrayList; import java.util.List; public class Main { public static List<Field> retrieveConstantFields(final Class<?> clazz) { final List<Field> fields = new ArrayList<Field>(); for (final Field field : retrieveAllFields(clazz)) { if (!isFieldToBeProvided(field)) { fields.add(field); }/*N o w J a v a . c o m - 时 代 Java 提供*/ } return fields; } public static List<Field> retrieveAllFields(final Class<?> clazz) { final List<Field> fields = new ArrayList<Field>(); Class<?> currentClass = clazz; while (!Object.class.equals(currentClass)) { for (final Field field : currentClass.getDeclaredFields()) { fields.add(field); } currentClass = currentClass.getSuperclass(); } return fields; } private static