Here you can find the source of findField(Class objectClass, String fieldName)
private static Field findField(Class objectClass, String fieldName)
//package com.java2s; // Licensed under the Apache License, Version 2.0 (the "License"); import java.lang.reflect.Field; public class Main { private static Field findField(Class objectClass, String fieldName) { Class cursor = objectClass; while (cursor != null) { try { return cursor.getDeclaredField(fieldName); } catch (NoSuchFieldException ex) { // Ignore. }/* ww w. j a v a 2 s . c o m*/ cursor = cursor.getSuperclass(); } throw new RuntimeException( String.format("Class %s does not contain a field named '%s'.", objectClass.getName(), fieldName)); } }