Here you can find the source of setField(Object obj, String fieldName, Object value, Class valueClass)
public final static void setField(Object obj, String fieldName, Object value, Class valueClass) throws NoSuchMethodException, IllegalAccessException, InvocationTargetException
//package com.java2s; import java.lang.reflect.Method; import java.lang.reflect.InvocationTargetException; public class Main { public final static void setField(Object obj, String fieldName, Object value, Class valueClass) throws NoSuchMethodException, IllegalAccessException, InvocationTargetException { if (obj == null || fieldName == null || fieldName.length() < 1) { return; }// w w w . j av a2 s . c o m String methodName = "set" + Character.toUpperCase(fieldName.charAt(0)) + fieldName.substring(1); Method m = obj.getClass().getMethod(methodName, new Class[] { valueClass }); m.invoke(obj, new Object[] { value }); } }