Here you can find the source of findFieldOfBean(Object bean, String fieldName)
public static Field findFieldOfBean(Object bean, String fieldName)
//package com.java2s; import java.lang.reflect.Field; public class Main { public static Field findFieldOfBean(Object bean, String fieldName) { Field field = null;//from w w w.ja v a 2 s. c om Class<?> clazz = bean.getClass(); while (clazz != null && field == null) { field = findField(clazz.getDeclaredFields(), fieldName); clazz = clazz.getSuperclass(); } if (field == null) throw new IllegalStateException("Field " + fieldName + " not found"); return field; } public static Field findField(Field[] fields, String name) { for (Field field : fields) if (field.getName().equals(name)) return field; return null; } }