public static Field getField ( Class cls , String fieldname ) throws NoSuchFieldException { while ( true ) { try { return cls . getDeclaredField ( fieldname ) ; } catch ( NoSuchFieldException ex ) { cls = cls . getSuperclass ( ) ; if ( Object . class . equals ( cls ) ) { throw ex ; } } catch ( SecurityException ex ) { throw new IllegalArgumentException ( ex ) ; } } }
Returns Declared field either from given class or it s super class