Java tutorial
//package com.java2s; //License from project: Open Source License import java.lang.reflect.Field; public class Main { public static Field findField(Object src, String fieldName) throws Exception { return findField(src.getClass(), fieldName); } public static Field findField(Class src, String fieldName) throws Exception { try { return src.getDeclaredField(fieldName); } catch (Exception e) { if (src.getSuperclass() != null) { return findField(src.getSuperclass(), fieldName); } else { throw e; } } } }