get Declared Field - Android java.lang.reflect

Android examples for java.lang.reflect:Field

Description

get Declared Field

Demo Code


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

import android.util.Log;

public class Main {
    public static Field getDeclaredField(Object object, String fieldName) {
        Field field = null;//from   ww w .j a  v a2  s  .co  m

        Class<?> clazz = object.getClass();

        while (clazz != Object.class) {
            try {
                field = clazz.getDeclaredField(fieldName);
                return field;
            } catch (Exception e) {
                Log.i("ReflectUtil File", "");

                clazz = clazz.getSuperclass();
            }

        }

        return null;
    }
}

Related Tutorials