Here you can find the source of setFieldValue(Class> clazz, Object entity, String fieldName, V value)
public static <V> boolean setFieldValue(Class<?> clazz, Object entity, String fieldName, V value)
//package com.java2s; //License from project: Apache License import java.lang.reflect.Field; public class Main { public static <E, V> boolean setFieldValue(E entity, String fieldName, V value) { return setFieldValue(entity.getClass(), entity, fieldName, value); }/*from ww w. j a v a2 s. c o m*/ public static <V> boolean setFieldValue(Class<?> clazz, Object entity, String fieldName, V value) { try { Field f = clazz.getDeclaredField(fieldName); f.setAccessible(true); f.set(entity, value); return true; } catch (Exception ex) { throw new RuntimeException("Cannot set field " + fieldName + " value to " + value, ex); } } }