Java tutorial
//package com.java2s; //License from project: Open Source License import java.lang.reflect.Field; public class Main { private static Field prepareField(Class c, String fieldName) throws NoSuchFieldException { while (c != null) { try { Field f = c.getDeclaredField(fieldName); f.setAccessible(true); return f; } catch (Exception e) { } finally { c = c.getSuperclass(); } } throw new NoSuchFieldException(); } }