Here you can find the source of setFieldValue(Class c, Object instance, String name, Object value)
public static void setFieldValue(Class c, Object instance, String name, Object value)
//package com.java2s; //License from project: Apache License import java.lang.reflect.Field; public class Main { public static void setFieldValue(Class c, Object instance, String name, Object value) { try {/*from ww w.j a v a 2s .c o m*/ Field declaredField = c.getDeclaredField(name); declaredField.setAccessible(true); declaredField.set(instance, value); } catch (IllegalAccessException e) { throw new RuntimeException(e); } catch (NoSuchFieldException e) { throw new RuntimeException(e); } } }