public static Field findField ( Class < ? > type , String fieldName ) { while ( type != null ) { Field [ ] fields = type . getDeclaredFields ( ) ; for ( Field field : fields ) { if ( field . getName ( ) . equals ( fieldName ) ) return field ; } type = type . getSuperclass ( ) ; } return null ; }
Find the field with the given name in the class . Will inspect all fields independent of access level .