Java tutorial
//package com.java2s; import java.lang.reflect.Field; public class Main { public static void setField(Class cls, String name, Object obj, Object value) { try { Field nameField = cls.getDeclaredField(name); nameField.setAccessible(true); nameField.set(obj, value); } catch (Exception e) { e.printStackTrace(); } } }