Here you can find the source of setFieldValue(Class extends E> clazz, E instance, Object value, String... names)
public static <T, E> void setFieldValue(Class<? extends E> clazz, E instance, Object value, String... names)
//package com.java2s; //License from project: Open Source License import java.lang.reflect.Field; public class Main { public static <T, E> void setFieldValue(Class<? extends E> clazz, E instance, Object value, String... names) { try {/*from w w w . ja v a2 s . co m*/ Field field = getField(clazz, names); if (field != null) field.set(instance, value); } catch (Exception e) { } } public static Field getField(Class<?> clazz, String... names) { try { Field[] fields = clazz.getDeclaredFields(); for (Field field : fields) { for (String fieldName : names) { if (field.getName().equalsIgnoreCase(fieldName)) { field.setAccessible(true); return field; } } } } catch (Exception e) { throw e; } return null; } }