public static void setFieldValue ( Field field , Object obj , Object value ) { if ( Modifier . isFinal ( field . getModifiers ( ) ) ) { Object finalValue = getFieldValue ( field , obj ) ; if ( value == null ? finalValue != null : ! value . equals ( finalValue ) ) { throw new IllegalArgumentException ( "expected final value <" + finalValue + "> but was <" + value + "> on " + field . getName ( ) + " field in " + obj . getClass ( ) . getName ( ) ) ; } } else { try { field . set ( obj , value ) ; } catch ( SecurityException e ) { throw new IllegalArgumentException ( e ) ; } catch ( IllegalAccessException e ) { throw new IllegalArgumentException ( e ) ; } } }
Sets the given field in the given object to the given value using reflection .