Here you can find the source of setField(java.lang.Object toObj, String tcFieldName, java.lang.Object toNewValue)
public static void setField(java.lang.Object toObj, String tcFieldName, java.lang.Object toNewValue)
//package com.java2s; //License from project: Open Source License import java.lang.reflect.Field; public class Main { public static void setField(java.lang.Object toObj, String tcFieldName, java.lang.Object toNewValue) { try {/*from w w w.j av a2 s .c o m*/ Field loField = toObj.getClass().getDeclaredField(tcFieldName); loField.setAccessible(true); loField.set(toObj, toNewValue); } catch (IllegalArgumentException ex) { throw new RuntimeException(ex); } catch (IllegalAccessException ex) { throw new RuntimeException(ex); } catch (NoSuchFieldException ex) { throw new RuntimeException(ex); } catch (SecurityException ex) { throw new RuntimeException(ex); } } }