//package com.nowjava;/** from 时代Java公众号 - nowjava.com**/
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
public class Main {
public static void main(String[] argv) throws Exception {
Class clazz = String.class;
System.out.println(getDeclaredFieldsInLineage(clazz));
}
/**
来自 n o w j a v a . c o m - 时 代 Java**/
/**
* Returns an array of {@code Field} objects reflecting all the fields declared by the class including the fields of
* the superclasses as well.
* <p/>
* This method matches the same kinds of fields that are returned by {@link Class#getDeclaredFields()} with the
* exception that it includes fields inherited from the superclasses. This means public, protected, default
* (package) access, and private fields AND fields of those types inherited from the superclasses.
* <p/>
* The returned list is partially ordered. Results from more derived classes show up earlier in the list. Within the
* set of fields for the same class, however, the order is undefined.
*
* @param clazz the class
* @return the array of {@code Field} objects representing all the declared fields of this class
* @see Class#getDeclaredFields() for more details
*/
public static List<Field> getDeclaredFieldsInLineage(Class<?> clazz) {
List<Field> fields = new ArrayList<Field>(Arrays.asList(clazz
/**代码未完, 请加载全部代码(NowJava.com).**/
本文系作者在时代Java发表,未经许可,不得转载。如有侵权,请联系nowjava@qq.com删除。