Java tutorial
//package com.java2s; import java.lang.reflect.Field; public class Main { private static void setField(Object obj, Class<?> cls, String field, Object value) { try { Field localField = cls.getDeclaredField(field); localField.setAccessible(true); localField.set(obj, value); } catch (NoSuchFieldException e) { e.printStackTrace(); } catch (IllegalAccessException e) { e.printStackTrace(); } } }