Java tutorial
//package com.java2s; //License from project: Open Source License import java.lang.reflect.Field; public class Main { public static Field findFieldByClassAndTypeAndName(Class<?> targetObject, Class<?> fieldType, String fieldName) { Class clazz = targetObject; do { for (Field field : clazz.getDeclaredFields()) { if (field.getType() == fieldType && field.getName().equals(fieldName)) { field.setAccessible(true); return field; } } clazz = clazz.getSuperclass(); } while (clazz != null); throw new NoSuchFieldError("Field of type " + fieldType.getName() + " in class " + targetObject.getName()); } }