private Field getFieldRecursive ( Class c , String name ) throws NoSuchFieldException { try { return c . getDeclaredField ( name ) ; } catch ( NoSuchFieldException e ) { // if field could not be found in the inheritance hierarchy, signal error if ( ( c == Object . class ) || ( c . getSuperclass ( ) == null ) || c . isInterface ( ) ) { throw e ; } // if field could not be found in class c try in superclass else { return getFieldRecursive ( c . getSuperclass ( ) , name ) ; } } }
try to find a field in class c recurse through class hierarchy if necessary