reflect Class Field - Android java.lang.reflect

Android examples for java.lang.reflect:Field

Description

reflect Class Field

Demo Code


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

import android.text.TextUtils;

public class Main {
    public static Field reflectClassField(Class<?> clazz, String fieldName,
            boolean isEqualsIgnoreCase) {
        if (clazz == null || TextUtils.isEmpty(fieldName))
            return null;

        Field[] fields = clazz.getDeclaredFields();
        for (Field field : fields) {
            if ((isEqualsIgnoreCase && fieldName.equalsIgnoreCase(field
                    .getName())) || fieldName.equals(field.getName())) {
                return field;
            }/*from w  w w .jav  a 2s  .  co  m*/
        }
        return null;
    }
}

Related Tutorials