Here you can find the source of findField(Class c, Class fieldtype)
public static Field findField(Class c, Class fieldtype) throws Exception
//package com.java2s; //License from project: Open Source License import java.lang.reflect.Field; public class Main { public static Field findField(Class c, Class fieldtype) throws Exception { while (c != null && c != Object.class) { for (Field field : c.getDeclaredFields()) { if (field.getType() == fieldtype) { return field; }/*from w w w. j a va 2s . c o m*/ } c = c.getSuperclass(); } return null; } public static Field findField(Class c, String name) throws Exception { while (c != null && c != Object.class) { Field f = c.getDeclaredField(name); if (f != null) { return f; } c = c.getSuperclass(); } return null; } }