public static Field getRequiredField ( Class type , String name ) { try { return type . getDeclaredField ( name ) ; } catch ( NoSuchFieldException e ) { Optional < Field > field = findField ( type , name ) ; return field . orElseThrow ( ( ) -> new NoSuchFieldError ( "No field '" + name + "' found for type: " + type . getName ( ) ) ) ; } }
Finds a field on the given type for the given name .