get Declared Fields Include Inherit - Android java.lang.reflect

Android examples for java.lang.reflect:Field

Description

get Declared Fields Include Inherit

Demo Code


//package com.java2s;
import java.lang.reflect.Field;

import java.util.ArrayList;
import java.util.List;

public class Main {
    public static List<Field[]> getDeclaredFieldsIncludeInherit(
            Class<?> clazz) {
        List<Field[]> list = new ArrayList<Field[]>();
        for (Class<?> c = clazz; c != null; c = c.getSuperclass()) {
            Field[] fields = c.getDeclaredFields();
            list.add(fields);/*  w  w  w .  j  a  v  a 2  s  .  c  o m*/
        }
        return list;
    }
}

Related Tutorials