set Reflect Field - Android java.lang.reflect

Android examples for java.lang.reflect:Field

Description

set Reflect Field

Demo Code


//package com.java2s;

import java.lang.reflect.Field;

public class Main {
    public static void setReflectField(Object obj, String field,
            Object value) {/*from  ww w.  j  ava 2 s  .com*/
        try {
            Field f = null;
            try {
                f = obj.getClass().getDeclaredField(field);
            } catch (Exception e) {
                f = obj.getClass().getField(field);
            }

            f.setAccessible(true);
            f.set(obj, value);
        } catch (Exception e) {

        }
    }
}

Related Tutorials