Field.set

Field.set

Class Overview | Class Members | This Package | All Packages

Syntax
public native void set( Object obj, Object value ) throws IllegalArgumentException, IllegalAccessException
Description
Sets the field represented by this Field object on the specified object argument to the specified new value. The new value is automatically unwrapped if the underlying field has a primitive type.

The operation proceeds as follows:

If the underlying field is static, the object argument is ignored; it may be null.

Otherwise the underlying field is an instance field. If the specified object argument is null, the method throws a NullPointerException. If the specified object argument is not an instance of the class or interface declaring the underlying field, the method throws an IllegalArgumentException.

If this Field object enforces Java language access control, and the underlying field is inaccessible, the method throws an IllegalAccessException.

If the underlying field is final, the method throws an IllegalAccessException.

If the underlying field is of a primitive type, an unwrapping conversion is attempted to convert the new value to a value of a primitive type. If this attempt fails, the method throws an IllegalArgumentException.

If, after possible unwrapping, the new value cannot be converted to the type of the underlying field by an identity or widening conversion, the method throws an IllegalArgumentException.

The field is set to the possibly unwrapped and widened new value.

Exceptions
IllegalAccessException if the underlying constructor is inaccessible.
Exceptions
IllegalArgumentException if the specified object is not an instance of the class or interface declaring the underlying field, or if an unwrapping conversion fails.
Exceptions
NullPointerException if the specified object is null.