Here you can find the source of findField(Class> clazz, String field, Class> type, int index)
public static Field findField(Class<?> clazz, String field, Class<?> type, int index)
//package com.java2s; //License from project: Open Source License import java.lang.reflect.Field; public class Main { public static Field findField(Class<?> clazz, String field, Class<?> type, int index) { int temp = index; for (Field f : clazz.getDeclaredFields()) if ((field == null || f.getName().equals(field)) && type.isAssignableFrom(f.getType()) && temp-- <= 0) return f; if (clazz.getSuperclass() != null) return findField(clazz.getSuperclass(), field, type, index); return null; }/*from www. ja v a2 s.co m*/ }