Here you can find the source of setField(Object sourceObj, Object targetObj, Field valueField, List
private static void setField(Object sourceObj, Object targetObj, Field valueField, List<Field> targetFields)
//package com.java2s; //License from project: Open Source License import java.lang.reflect.Field; import java.util.*; public class Main { private static void setField(Object sourceObj, Object targetObj, Field valueField, List<Field> targetFields) { valueField.setAccessible(true);/*from w w w .j av a 2s .c om*/ for (Field target : targetFields) { if (target.getName().equals(valueField.getName())) { target.setAccessible(true); //System.out.println("setting field -> dto:" + valueField.getName() + ", entity:" + target.getName()); try { target.set(targetObj, valueField.get(sourceObj)); } catch (IllegalAccessException e) { e.printStackTrace(); } break; } } } }