Reflect Super Field Value - Android java.lang.reflect

Android examples for java.lang.reflect:Field Value

Description

Reflect Super Field Value

Demo Code


//package com.java2s;
import java.lang.reflect.Field;
import android.util.Log;

public class Main {
    private static String TAG = "ReflectUtil";

    public static Object ReflectSuperFieldValue(Class<?> clazz,
            Object classObj, String FieldName) {
        try {//from ww w.  j av a 2  s . c om
            Field field = clazz.getSuperclass().getDeclaredField(FieldName);
            return field.get(classObj);
        } catch (SecurityException e) {
            Log.e(TAG,
                    "ReflectSuperFieldValue SecurityException : "
                            + e.toString());
        } catch (NoSuchFieldException e) {
            Log.e(TAG,
                    "ReflectSuperFieldValue NoSuchFieldException : "
                            + e.toString());
        } catch (IllegalArgumentException e) {
            Log.e(TAG, "ReflectSuperFieldValue IllegalArgumentException : "
                    + e.toString());
        } catch (IllegalAccessException e) {
            Log.e(TAG, "ReflectSuperFieldValue IllegalAccessException : "
                    + e.toString());
        }
        return null;
    }
}

Related Tutorials