jdk/src/share/classes/java/lang/reflect/Field.java
changeset 9022 b2e8758b10fd
parent 5506 202f599c92aa
child 9029 e92fcf58f684
equal deleted inserted replaced
9021:5cf29386a520 9022:b2e8758b10fd
   338      * specified {@code obj} argument is null, the method throws a
   338      * specified {@code obj} argument is null, the method throws a
   339      * {@code NullPointerException}. If the specified object is not an
   339      * {@code NullPointerException}. If the specified object is not an
   340      * instance of the class or interface declaring the underlying
   340      * instance of the class or interface declaring the underlying
   341      * field, the method throws an {@code IllegalArgumentException}.
   341      * field, the method throws an {@code IllegalArgumentException}.
   342      *
   342      *
   343      * <p>If this {@code Field} object enforces Java language access control, and
   343      * <p>If this {@code Field} object is enforcing Java language access control, and
   344      * the underlying field is inaccessible, the method throws an
   344      * the underlying field is inaccessible, the method throws an
   345      * {@code IllegalAccessException}.
   345      * {@code IllegalAccessException}.
   346      * If the underlying field is static, the class that declared the
   346      * If the underlying field is static, the class that declared the
   347      * field is initialized if it has not already been initialized.
   347      * field is initialized if it has not already been initialized.
   348      *
   348      *
   358      * to be extracted
   358      * to be extracted
   359      * @return the value of the represented field in object
   359      * @return the value of the represented field in object
   360      * {@code obj}; primitive values are wrapped in an appropriate
   360      * {@code obj}; primitive values are wrapped in an appropriate
   361      * object before being returned
   361      * object before being returned
   362      *
   362      *
   363      * @exception IllegalAccessException    if the underlying field
   363      * @exception IllegalAccessException    if this {@code Field} object
   364      *              is inaccessible.
   364      *              is enforcing Java language access control and the underlying
       
   365      *              field is inaccessible.
   365      * @exception IllegalArgumentException  if the specified object is not an
   366      * @exception IllegalArgumentException  if the specified object is not an
   366      *              instance of the class or interface declaring the underlying
   367      *              instance of the class or interface declaring the underlying
   367      *              field (or a subclass or implementor thereof).
   368      *              field (or a subclass or implementor thereof).
   368      * @exception NullPointerException      if the specified object is null
   369      * @exception NullPointerException      if the specified object is null
   369      *              and the field is an instance field.
   370      *              and the field is an instance field.
   381      *
   382      *
   382      * @param obj the object to extract the {@code boolean} value
   383      * @param obj the object to extract the {@code boolean} value
   383      * from
   384      * from
   384      * @return the value of the {@code boolean} field
   385      * @return the value of the {@code boolean} field
   385      *
   386      *
   386      * @exception IllegalAccessException    if the underlying field
   387      * @exception IllegalAccessException    if this {@code Field} object
   387      *              is inaccessible.
   388      *              is enforcing Java language access control and the underlying
       
   389      *              field is inaccessible.
   388      * @exception IllegalArgumentException  if the specified object is not
   390      * @exception IllegalArgumentException  if the specified object is not
   389      *              an instance of the class or interface declaring the
   391      *              an instance of the class or interface declaring the
   390      *              underlying field (or a subclass or implementor
   392      *              underlying field (or a subclass or implementor
   391      *              thereof), or if the field value cannot be
   393      *              thereof), or if the field value cannot be
   392      *              converted to the type {@code boolean} by a
   394      *              converted to the type {@code boolean} by a
   408      *
   410      *
   409      * @param obj the object to extract the {@code byte} value
   411      * @param obj the object to extract the {@code byte} value
   410      * from
   412      * from
   411      * @return the value of the {@code byte} field
   413      * @return the value of the {@code byte} field
   412      *
   414      *
   413      * @exception IllegalAccessException    if the underlying field
   415      * @exception IllegalAccessException    if this {@code Field} object
   414      *              is inaccessible.
   416      *              is enforcing Java language access control and the underlying
       
   417      *              field is inaccessible.
   415      * @exception IllegalArgumentException  if the specified object is not
   418      * @exception IllegalArgumentException  if the specified object is not
   416      *              an instance of the class or interface declaring the
   419      *              an instance of the class or interface declaring the
   417      *              underlying field (or a subclass or implementor
   420      *              underlying field (or a subclass or implementor
   418      *              thereof), or if the field value cannot be
   421      *              thereof), or if the field value cannot be
   419      *              converted to the type {@code byte} by a
   422      *              converted to the type {@code byte} by a
   437      *
   440      *
   438      * @param obj the object to extract the {@code char} value
   441      * @param obj the object to extract the {@code char} value
   439      * from
   442      * from
   440      * @return the value of the field converted to type {@code char}
   443      * @return the value of the field converted to type {@code char}
   441      *
   444      *
   442      * @exception IllegalAccessException    if the underlying field
   445      * @exception IllegalAccessException    if this {@code Field} object
   443      *              is inaccessible.
   446      *              is enforcing Java language access control and the underlying
       
   447      *              field is inaccessible.
   444      * @exception IllegalArgumentException  if the specified object is not
   448      * @exception IllegalArgumentException  if the specified object is not
   445      *              an instance of the class or interface declaring the
   449      *              an instance of the class or interface declaring the
   446      *              underlying field (or a subclass or implementor
   450      *              underlying field (or a subclass or implementor
   447      *              thereof), or if the field value cannot be
   451      *              thereof), or if the field value cannot be
   448      *              converted to the type {@code char} by a
   452      *              converted to the type {@code char} by a
   466      *
   470      *
   467      * @param obj the object to extract the {@code short} value
   471      * @param obj the object to extract the {@code short} value
   468      * from
   472      * from
   469      * @return the value of the field converted to type {@code short}
   473      * @return the value of the field converted to type {@code short}
   470      *
   474      *
   471      * @exception IllegalAccessException    if the underlying field
   475      * @exception IllegalAccessException    if this {@code Field} object
   472      *              is inaccessible.
   476      *              is enforcing Java language access control and the underlying
       
   477      *              field is inaccessible.
   473      * @exception IllegalArgumentException  if the specified object is not
   478      * @exception IllegalArgumentException  if the specified object is not
   474      *              an instance of the class or interface declaring the
   479      *              an instance of the class or interface declaring the
   475      *              underlying field (or a subclass or implementor
   480      *              underlying field (or a subclass or implementor
   476      *              thereof), or if the field value cannot be
   481      *              thereof), or if the field value cannot be
   477      *              converted to the type {@code short} by a
   482      *              converted to the type {@code short} by a
   495      *
   500      *
   496      * @param obj the object to extract the {@code int} value
   501      * @param obj the object to extract the {@code int} value
   497      * from
   502      * from
   498      * @return the value of the field converted to type {@code int}
   503      * @return the value of the field converted to type {@code int}
   499      *
   504      *
   500      * @exception IllegalAccessException    if the underlying field
   505      * @exception IllegalAccessException    if this {@code Field} object
   501      *              is inaccessible.
   506      *              is enforcing Java language access control and the underlying
       
   507      *              field is inaccessible.
   502      * @exception IllegalArgumentException  if the specified object is not
   508      * @exception IllegalArgumentException  if the specified object is not
   503      *              an instance of the class or interface declaring the
   509      *              an instance of the class or interface declaring the
   504      *              underlying field (or a subclass or implementor
   510      *              underlying field (or a subclass or implementor
   505      *              thereof), or if the field value cannot be
   511      *              thereof), or if the field value cannot be
   506      *              converted to the type {@code int} by a
   512      *              converted to the type {@code int} by a
   524      *
   530      *
   525      * @param obj the object to extract the {@code long} value
   531      * @param obj the object to extract the {@code long} value
   526      * from
   532      * from
   527      * @return the value of the field converted to type {@code long}
   533      * @return the value of the field converted to type {@code long}
   528      *
   534      *
   529      * @exception IllegalAccessException    if the underlying field
   535      * @exception IllegalAccessException    if this {@code Field} object
   530      *              is inaccessible.
   536      *              is enforcing Java language access control and the underlying
       
   537      *              field is inaccessible.
   531      * @exception IllegalArgumentException  if the specified object is not
   538      * @exception IllegalArgumentException  if the specified object is not
   532      *              an instance of the class or interface declaring the
   539      *              an instance of the class or interface declaring the
   533      *              underlying field (or a subclass or implementor
   540      *              underlying field (or a subclass or implementor
   534      *              thereof), or if the field value cannot be
   541      *              thereof), or if the field value cannot be
   535      *              converted to the type {@code long} by a
   542      *              converted to the type {@code long} by a
   553      *
   560      *
   554      * @param obj the object to extract the {@code float} value
   561      * @param obj the object to extract the {@code float} value
   555      * from
   562      * from
   556      * @return the value of the field converted to type {@code float}
   563      * @return the value of the field converted to type {@code float}
   557      *
   564      *
   558      * @exception IllegalAccessException    if the underlying field
   565      * @exception IllegalAccessException    if this {@code Field} object
   559      *              is inaccessible.
   566      *              is enforcing Java language access control and the underlying
       
   567      *              field is inaccessible.
   560      * @exception IllegalArgumentException  if the specified object is not
   568      * @exception IllegalArgumentException  if the specified object is not
   561      *              an instance of the class or interface declaring the
   569      *              an instance of the class or interface declaring the
   562      *              underlying field (or a subclass or implementor
   570      *              underlying field (or a subclass or implementor
   563      *              thereof), or if the field value cannot be
   571      *              thereof), or if the field value cannot be
   564      *              converted to the type {@code float} by a
   572      *              converted to the type {@code float} by a
   582      *
   590      *
   583      * @param obj the object to extract the {@code double} value
   591      * @param obj the object to extract the {@code double} value
   584      * from
   592      * from
   585      * @return the value of the field converted to type {@code double}
   593      * @return the value of the field converted to type {@code double}
   586      *
   594      *
   587      * @exception IllegalAccessException    if the underlying field
   595      * @exception IllegalAccessException    if this {@code Field} object
   588      *              is inaccessible.
   596      *              is enforcing Java language access control and the underlying
       
   597      *              field is inaccessible.
   589      * @exception IllegalArgumentException  if the specified object is not
   598      * @exception IllegalArgumentException  if the specified object is not
   590      *              an instance of the class or interface declaring the
   599      *              an instance of the class or interface declaring the
   591      *              underlying field (or a subclass or implementor
   600      *              underlying field (or a subclass or implementor
   592      *              thereof), or if the field value cannot be
   601      *              thereof), or if the field value cannot be
   593      *              converted to the type {@code double} by a
   602      *              converted to the type {@code double} by a
   619      * specified object argument is null, the method throws a
   628      * specified object argument is null, the method throws a
   620      * {@code NullPointerException}.  If the specified object argument is not
   629      * {@code NullPointerException}.  If the specified object argument is not
   621      * an instance of the class or interface declaring the underlying
   630      * an instance of the class or interface declaring the underlying
   622      * field, the method throws an {@code IllegalArgumentException}.
   631      * field, the method throws an {@code IllegalArgumentException}.
   623      *
   632      *
   624      * <p>If this {@code Field} object enforces Java language access control, and
   633      * <p>If this {@code Field} object is enforcing Java language access control, and
   625      * the underlying field is inaccessible, the method throws an
   634      * the underlying field is inaccessible, the method throws an
   626      * {@code IllegalAccessException}.
   635      * {@code IllegalAccessException}.
   627      *
   636      *
   628      * <p>If the underlying field is final, the method throws an
   637      * <p>If the underlying field is final, the method throws an
   629      * {@code IllegalAccessException} unless
   638      * {@code IllegalAccessException} unless {@code setAccessible(true)}
   630      * {@code setAccessible(true)} has succeeded for this field
   639      * has succeeded for this {@code Field} object
   631      * and this field is non-static. Setting a final field in this way
   640      * and the field is non-static. Setting a final field in this way
   632      * is meaningful only during deserialization or reconstruction of
   641      * is meaningful only during deserialization or reconstruction of
   633      * instances of classes with blank final fields, before they are
   642      * instances of classes with blank final fields, before they are
   634      * made available for access by other parts of a program. Use in
   643      * made available for access by other parts of a program. Use in
   635      * any other context may have unpredictable effects, including cases
   644      * any other context may have unpredictable effects, including cases
   636      * in which other parts of a program continue to use the original
   645      * in which other parts of a program continue to use the original
   656      *
   665      *
   657      * @param obj the object whose field should be modified
   666      * @param obj the object whose field should be modified
   658      * @param value the new value for the field of {@code obj}
   667      * @param value the new value for the field of {@code obj}
   659      * being modified
   668      * being modified
   660      *
   669      *
   661      * @exception IllegalAccessException    if the underlying field
   670      * @exception IllegalAccessException    if this {@code Field} object
   662      *              is inaccessible.
   671      *              is enforcing Java language access control and the underlying
       
   672      *              field is either inaccessible or final.
   663      * @exception IllegalArgumentException  if the specified object is not an
   673      * @exception IllegalArgumentException  if the specified object is not an
   664      *              instance of the class or interface declaring the underlying
   674      *              instance of the class or interface declaring the underlying
   665      *              field (or a subclass or implementor thereof),
   675      *              field (or a subclass or implementor thereof),
   666      *              or if an unwrapping conversion fails.
   676      *              or if an unwrapping conversion fails.
   667      * @exception NullPointerException      if the specified object is null
   677      * @exception NullPointerException      if the specified object is null
   684      *
   694      *
   685      * @param obj the object whose field should be modified
   695      * @param obj the object whose field should be modified
   686      * @param z   the new value for the field of {@code obj}
   696      * @param z   the new value for the field of {@code obj}
   687      * being modified
   697      * being modified
   688      *
   698      *
   689      * @exception IllegalAccessException    if the underlying field
   699      * @exception IllegalAccessException    if this {@code Field} object
   690      *              is inaccessible.
   700      *              is enforcing Java language access control and the underlying
       
   701      *              field is either inaccessible or final.
   691      * @exception IllegalArgumentException  if the specified object is not an
   702      * @exception IllegalArgumentException  if the specified object is not an
   692      *              instance of the class or interface declaring the underlying
   703      *              instance of the class or interface declaring the underlying
   693      *              field (or a subclass or implementor thereof),
   704      *              field (or a subclass or implementor thereof),
   694      *              or if an unwrapping conversion fails.
   705      *              or if an unwrapping conversion fails.
   695      * @exception NullPointerException      if the specified object is null
   706      * @exception NullPointerException      if the specified object is null
   713      *
   724      *
   714      * @param obj the object whose field should be modified
   725      * @param obj the object whose field should be modified
   715      * @param b   the new value for the field of {@code obj}
   726      * @param b   the new value for the field of {@code obj}
   716      * being modified
   727      * being modified
   717      *
   728      *
   718      * @exception IllegalAccessException    if the underlying field
   729      * @exception IllegalAccessException    if this {@code Field} object
   719      *              is inaccessible.
   730      *              is enforcing Java language access control and the underlying
       
   731      *              field is either inaccessible or final.
   720      * @exception IllegalArgumentException  if the specified object is not an
   732      * @exception IllegalArgumentException  if the specified object is not an
   721      *              instance of the class or interface declaring the underlying
   733      *              instance of the class or interface declaring the underlying
   722      *              field (or a subclass or implementor thereof),
   734      *              field (or a subclass or implementor thereof),
   723      *              or if an unwrapping conversion fails.
   735      *              or if an unwrapping conversion fails.
   724      * @exception NullPointerException      if the specified object is null
   736      * @exception NullPointerException      if the specified object is null
   742      *
   754      *
   743      * @param obj the object whose field should be modified
   755      * @param obj the object whose field should be modified
   744      * @param c   the new value for the field of {@code obj}
   756      * @param c   the new value for the field of {@code obj}
   745      * being modified
   757      * being modified
   746      *
   758      *
   747      * @exception IllegalAccessException    if the underlying field
   759      * @exception IllegalAccessException    if this {@code Field} object
   748      *              is inaccessible.
   760      *              is enforcing Java language access control and the underlying
       
   761      *              field is either inaccessible or final.
   749      * @exception IllegalArgumentException  if the specified object is not an
   762      * @exception IllegalArgumentException  if the specified object is not an
   750      *              instance of the class or interface declaring the underlying
   763      *              instance of the class or interface declaring the underlying
   751      *              field (or a subclass or implementor thereof),
   764      *              field (or a subclass or implementor thereof),
   752      *              or if an unwrapping conversion fails.
   765      *              or if an unwrapping conversion fails.
   753      * @exception NullPointerException      if the specified object is null
   766      * @exception NullPointerException      if the specified object is null
   771      *
   784      *
   772      * @param obj the object whose field should be modified
   785      * @param obj the object whose field should be modified
   773      * @param s   the new value for the field of {@code obj}
   786      * @param s   the new value for the field of {@code obj}
   774      * being modified
   787      * being modified
   775      *
   788      *
   776      * @exception IllegalAccessException    if the underlying field
   789      * @exception IllegalAccessException    if this {@code Field} object
   777      *              is inaccessible.
   790      *              is enforcing Java language access control and the underlying
       
   791      *              field is either inaccessible or final.
   778      * @exception IllegalArgumentException  if the specified object is not an
   792      * @exception IllegalArgumentException  if the specified object is not an
   779      *              instance of the class or interface declaring the underlying
   793      *              instance of the class or interface declaring the underlying
   780      *              field (or a subclass or implementor thereof),
   794      *              field (or a subclass or implementor thereof),
   781      *              or if an unwrapping conversion fails.
   795      *              or if an unwrapping conversion fails.
   782      * @exception NullPointerException      if the specified object is null
   796      * @exception NullPointerException      if the specified object is null
   800      *
   814      *
   801      * @param obj the object whose field should be modified
   815      * @param obj the object whose field should be modified
   802      * @param i   the new value for the field of {@code obj}
   816      * @param i   the new value for the field of {@code obj}
   803      * being modified
   817      * being modified
   804      *
   818      *
   805      * @exception IllegalAccessException    if the underlying field
   819      * @exception IllegalAccessException    if this {@code Field} object
   806      *              is inaccessible.
   820      *              is enforcing Java language access control and the underlying
       
   821      *              field is either inaccessible or final.
   807      * @exception IllegalArgumentException  if the specified object is not an
   822      * @exception IllegalArgumentException  if the specified object is not an
   808      *              instance of the class or interface declaring the underlying
   823      *              instance of the class or interface declaring the underlying
   809      *              field (or a subclass or implementor thereof),
   824      *              field (or a subclass or implementor thereof),
   810      *              or if an unwrapping conversion fails.
   825      *              or if an unwrapping conversion fails.
   811      * @exception NullPointerException      if the specified object is null
   826      * @exception NullPointerException      if the specified object is null
   829      *
   844      *
   830      * @param obj the object whose field should be modified
   845      * @param obj the object whose field should be modified
   831      * @param l   the new value for the field of {@code obj}
   846      * @param l   the new value for the field of {@code obj}
   832      * being modified
   847      * being modified
   833      *
   848      *
   834      * @exception IllegalAccessException    if the underlying field
   849      * @exception IllegalAccessException    if this {@code Field} object
   835      *              is inaccessible.
   850      *              is enforcing Java language access control and the underlying
       
   851      *              field is either inaccessible or final.
   836      * @exception IllegalArgumentException  if the specified object is not an
   852      * @exception IllegalArgumentException  if the specified object is not an
   837      *              instance of the class or interface declaring the underlying
   853      *              instance of the class or interface declaring the underlying
   838      *              field (or a subclass or implementor thereof),
   854      *              field (or a subclass or implementor thereof),
   839      *              or if an unwrapping conversion fails.
   855      *              or if an unwrapping conversion fails.
   840      * @exception NullPointerException      if the specified object is null
   856      * @exception NullPointerException      if the specified object is null
   858      *
   874      *
   859      * @param obj the object whose field should be modified
   875      * @param obj the object whose field should be modified
   860      * @param f   the new value for the field of {@code obj}
   876      * @param f   the new value for the field of {@code obj}
   861      * being modified
   877      * being modified
   862      *
   878      *
   863      * @exception IllegalAccessException    if the underlying field
   879      * @exception IllegalAccessException    if this {@code Field} object
   864      *              is inaccessible.
   880      *              is enforcing Java language access control and the underlying
       
   881      *              field is either inaccessible or final.
   865      * @exception IllegalArgumentException  if the specified object is not an
   882      * @exception IllegalArgumentException  if the specified object is not an
   866      *              instance of the class or interface declaring the underlying
   883      *              instance of the class or interface declaring the underlying
   867      *              field (or a subclass or implementor thereof),
   884      *              field (or a subclass or implementor thereof),
   868      *              or if an unwrapping conversion fails.
   885      *              or if an unwrapping conversion fails.
   869      * @exception NullPointerException      if the specified object is null
   886      * @exception NullPointerException      if the specified object is null
   887      *
   904      *
   888      * @param obj the object whose field should be modified
   905      * @param obj the object whose field should be modified
   889      * @param d   the new value for the field of {@code obj}
   906      * @param d   the new value for the field of {@code obj}
   890      * being modified
   907      * being modified
   891      *
   908      *
   892      * @exception IllegalAccessException    if the underlying field
   909      * @exception IllegalAccessException    if this {@code Field} object
   893      *              is inaccessible.
   910      *              is enforcing Java language access control and the underlying
       
   911      *              field is either inaccessible or final.
   894      * @exception IllegalArgumentException  if the specified object is not an
   912      * @exception IllegalArgumentException  if the specified object is not an
   895      *              instance of the class or interface declaring the underlying
   913      *              instance of the class or interface declaring the underlying
   896      *              field (or a subclass or implementor thereof),
   914      *              field (or a subclass or implementor thereof),
   897      *              or if an unwrapping conversion fails.
   915      *              or if an unwrapping conversion fails.
   898      * @exception NullPointerException      if the specified object is null
   916      * @exception NullPointerException      if the specified object is null