Here you can find the source of findField(final Object src, final String fieldName)
private static Field findField(final Object src, final String fieldName) throws NoSuchFieldException
//package com.java2s; //License from project: Apache License import java.lang.reflect.Field; public class Main { private static Field findField(final Object src, final String fieldName) throws NoSuchFieldException { Class<?> current = src.getClass(); Field field = null;//from w ww . j a va 2 s . co m while (current != null && field == null) { field = getField(current, fieldName); current = current.getSuperclass(); } if (field == null) { throw new NoSuchFieldException(src + " does not declare " + fieldName); } return field; } private static Field getField(Class<?> clazz, final String fieldName) { for (Field field : clazz.getDeclaredFields()) { if (field.getName().equals(fieldName)) { return field; } } return null; } }