日期:2014-05-20 浏览次数:20929 次
public class User { private String name; public User() { } }
protected final void injectField(Object source, String fieldName, Object fieldValue) { try { Field field = source.getClass().getDeclaredField(fieldName); field.setAccessible(true); field.set(source, fieldValue); } catch (Exception e) { throw new IllegalStateException(e); } }