get Field from current class or parent class - Android java.lang.reflect

Android examples for java.lang.reflect:Field

Description

get Field from current class or parent class

Demo Code


//package com.java2s;

import java.lang.reflect.Field;

public class Main {
    public static Field getField(Class clazz, boolean fieldDeclaredInClass,
            String fieldName) throws Exception {
        if (fieldDeclaredInClass)
            return clazz.getDeclaredField(fieldName);
        else//from   w  w w  . j a  va2 s . com
            return clazz.getField(fieldName);
    }
}

Related Tutorials