< prev index next >

src/java.base/share/classes/java/lang/reflect/Field.java

Print this page




 707      * primitive type.
 708      *
 709      * <p>The operation proceeds as follows:
 710      *
 711      * <p>If the underlying field is static, the {@code obj} argument is
 712      * ignored; it may be null.
 713      *
 714      * <p>Otherwise the underlying field is an instance field.  If the
 715      * specified object argument is null, the method throws a
 716      * {@code NullPointerException}.  If the specified object argument is not
 717      * an instance of the class or interface declaring the underlying
 718      * field, the method throws an {@code IllegalArgumentException}.
 719      *
 720      * <p>If this {@code Field} object is enforcing Java language access control, and
 721      * the underlying field is inaccessible, the method throws an
 722      * {@code IllegalAccessException}.
 723      *
 724      * <p>If the underlying field is final, the method throws an
 725      * {@code IllegalAccessException} unless {@code setAccessible(true)}
 726      * has succeeded for this {@code Field} object
 727      * and the field is non-static. Setting a final field in this way


 728      * is meaningful only during deserialization or reconstruction of
 729      * instances of classes with blank final fields, before they are
 730      * made available for access by other parts of a program. Use in
 731      * any other context may have unpredictable effects, including cases
 732      * in which other parts of a program continue to use the original
 733      * value of this field.
 734      *
 735      * <p>If the underlying field is of a primitive type, an unwrapping
 736      * conversion is attempted to convert the new value to a value of
 737      * a primitive type.  If this attempt fails, the method throws an
 738      * {@code IllegalArgumentException}.
 739      *
 740      * <p>If, after possible unwrapping, the new value cannot be
 741      * converted to the type of the underlying field by an identity or
 742      * widening conversion, the method throws an
 743      * {@code IllegalArgumentException}.
 744      *
 745      * <p>If the underlying field is static, the class that declared the
 746      * field is initialized if it has not already been initialized.
 747      *




 707      * primitive type.
 708      *
 709      * <p>The operation proceeds as follows:
 710      *
 711      * <p>If the underlying field is static, the {@code obj} argument is
 712      * ignored; it may be null.
 713      *
 714      * <p>Otherwise the underlying field is an instance field.  If the
 715      * specified object argument is null, the method throws a
 716      * {@code NullPointerException}.  If the specified object argument is not
 717      * an instance of the class or interface declaring the underlying
 718      * field, the method throws an {@code IllegalArgumentException}.
 719      *
 720      * <p>If this {@code Field} object is enforcing Java language access control, and
 721      * the underlying field is inaccessible, the method throws an
 722      * {@code IllegalAccessException}.
 723      *
 724      * <p>If the underlying field is final, the method throws an
 725      * {@code IllegalAccessException} unless {@code setAccessible(true)}
 726      * has succeeded for this {@code Field} object
 727      * and the field is non-static and its declaring class is not
 728      * a {@linkplain Class#isHiddenClass() hidden} class.
 729      * Setting a final field in this way
 730      * is meaningful only during deserialization or reconstruction of
 731      * instances of classes with blank final fields, before they are
 732      * made available for access by other parts of a program. Use in
 733      * any other context may have unpredictable effects, including cases
 734      * in which other parts of a program continue to use the original
 735      * value of this field.
 736      *
 737      * <p>If the underlying field is of a primitive type, an unwrapping
 738      * conversion is attempted to convert the new value to a value of
 739      * a primitive type.  If this attempt fails, the method throws an
 740      * {@code IllegalArgumentException}.
 741      *
 742      * <p>If, after possible unwrapping, the new value cannot be
 743      * converted to the type of the underlying field by an identity or
 744      * widening conversion, the method throws an
 745      * {@code IllegalArgumentException}.
 746      *
 747      * <p>If the underlying field is static, the class that declared the
 748      * field is initialized if it has not already been initialized.
 749      *


< prev index next >