Android Field Set setFieldValue(Object obj, String propertyName, Object value)

Here you can find the source of setFieldValue(Object obj, String propertyName, Object value)

Description

set Field Value

Declaration

public static void setFieldValue(Object obj, String propertyName,
        Object value) 

Method Source Code

//package com.java2s;

import java.lang.reflect.Field;

public class Main {

    public static void setFieldValue(Object obj, String propertyName,
            Object value) {/* w  w w. j ava2 s  .  com*/
        try {
            Field field = obj.getClass().getDeclaredField(propertyName);
            field.setAccessible(true);
            field.set(obj, value);
        } catch (Exception ex) {
            throw new RuntimeException();
        }
    }
}

Related

  1. setFieldValue(Object obj, String name, Object value)