Here you can find the source of findField(Object obj, String name)
private static Field findField(Object obj, String name)
//package com.java2s; //License from project: Open Source License import java.lang.reflect.Field; public class Main { private static Field findField(Object obj, String name) { Class<?> cl = obj.getClass(); while (cl != null) { try { Field field = cl.getDeclaredField(name); if (!field.isAccessible()) { field.setAccessible(true); }/* w w w. j a v a2 s . co m*/ return field; } catch (NoSuchFieldException e) { cl = cl.getSuperclass(); } } throw new IllegalArgumentException("Field " + name + " not found in " + obj.getClass().getName()); } }