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

Print this page




 343      * <p>If this {@code Field} object enforces Java language access control, and
 344      * the underlying field is inaccessible, the method throws an
 345      * {@code IllegalAccessException}.
 346      * If the underlying field is static, the class that declared the
 347      * field is initialized if it has not already been initialized.
 348      *
 349      * <p>Otherwise, the value is retrieved from the underlying instance
 350      * or static field.  If the field has a primitive type, the value
 351      * is wrapped in an object before being returned, otherwise it is
 352      * returned as is.
 353      *
 354      * <p>If the field is hidden in the type of {@code obj},
 355      * the field's value is obtained according to the preceding rules.
 356      *
 357      * @param obj object from which the represented field's value is
 358      * to be extracted
 359      * @return the value of the represented field in object
 360      * {@code obj}; primitive values are wrapped in an appropriate
 361      * object before being returned
 362      *
 363      * @exception IllegalAccessException    if the underlying field
 364      *              is inaccessible.

 365      * @exception IllegalArgumentException  if the specified object is not an
 366      *              instance of the class or interface declaring the underlying
 367      *              field (or a subclass or implementor thereof).
 368      * @exception NullPointerException      if the specified object is null
 369      *              and the field is an instance field.
 370      * @exception ExceptionInInitializerError if the initialization provoked
 371      *              by this method fails.
 372      */
 373     public Object get(Object obj)
 374         throws IllegalArgumentException, IllegalAccessException
 375     {
 376         return getFieldAccessor(obj).get(obj);
 377     }
 378 
 379     /**
 380      * Gets the value of a static or instance {@code boolean} field.
 381      *
 382      * @param obj the object to extract the {@code boolean} value
 383      * from
 384      * @return the value of the {@code boolean} field
 385      *
 386      * @exception IllegalAccessException    if the underlying field
 387      *              is inaccessible.

 388      * @exception IllegalArgumentException  if the specified object is not
 389      *              an instance of the class or interface declaring the
 390      *              underlying field (or a subclass or implementor
 391      *              thereof), or if the field value cannot be
 392      *              converted to the type {@code boolean} by a
 393      *              widening conversion.
 394      * @exception NullPointerException      if the specified object is null
 395      *              and the field is an instance field.
 396      * @exception ExceptionInInitializerError if the initialization provoked
 397      *              by this method fails.
 398      * @see       Field#get
 399      */
 400     public boolean getBoolean(Object obj)
 401         throws IllegalArgumentException, IllegalAccessException
 402     {
 403         return getFieldAccessor(obj).getBoolean(obj);
 404     }
 405 
 406     /**
 407      * Gets the value of a static or instance {@code byte} field.
 408      *
 409      * @param obj the object to extract the {@code byte} value
 410      * from
 411      * @return the value of the {@code byte} field
 412      *
 413      * @exception IllegalAccessException    if the underlying field
 414      *              is inaccessible.

 415      * @exception IllegalArgumentException  if the specified object is not
 416      *              an instance of the class or interface declaring the
 417      *              underlying field (or a subclass or implementor
 418      *              thereof), or if the field value cannot be
 419      *              converted to the type {@code byte} by a
 420      *              widening conversion.
 421      * @exception NullPointerException      if the specified object is null
 422      *              and the field is an instance field.
 423      * @exception ExceptionInInitializerError if the initialization provoked
 424      *              by this method fails.
 425      * @see       Field#get
 426      */
 427     public byte getByte(Object obj)
 428         throws IllegalArgumentException, IllegalAccessException
 429     {
 430         return getFieldAccessor(obj).getByte(obj);
 431     }
 432 
 433     /**
 434      * Gets the value of a static or instance field of type
 435      * {@code char} or of another primitive type convertible to
 436      * type {@code char} via a widening conversion.
 437      *
 438      * @param obj the object to extract the {@code char} value
 439      * from
 440      * @return the value of the field converted to type {@code char}
 441      *
 442      * @exception IllegalAccessException    if the underlying field
 443      *              is inaccessible.

 444      * @exception IllegalArgumentException  if the specified object is not
 445      *              an instance of the class or interface declaring the
 446      *              underlying field (or a subclass or implementor
 447      *              thereof), or if the field value cannot be
 448      *              converted to the type {@code char} by a
 449      *              widening conversion.
 450      * @exception NullPointerException      if the specified object is null
 451      *              and the field is an instance field.
 452      * @exception ExceptionInInitializerError if the initialization provoked
 453      *              by this method fails.
 454      * @see Field#get
 455      */
 456     public char getChar(Object obj)
 457         throws IllegalArgumentException, IllegalAccessException
 458     {
 459         return getFieldAccessor(obj).getChar(obj);
 460     }
 461 
 462     /**
 463      * Gets the value of a static or instance field of type
 464      * {@code short} or of another primitive type convertible to
 465      * type {@code short} via a widening conversion.
 466      *
 467      * @param obj the object to extract the {@code short} value
 468      * from
 469      * @return the value of the field converted to type {@code short}
 470      *
 471      * @exception IllegalAccessException    if the underlying field
 472      *              is inaccessible.

 473      * @exception IllegalArgumentException  if the specified object is not
 474      *              an instance of the class or interface declaring the
 475      *              underlying field (or a subclass or implementor
 476      *              thereof), or if the field value cannot be
 477      *              converted to the type {@code short} by a
 478      *              widening conversion.
 479      * @exception NullPointerException      if the specified object is null
 480      *              and the field is an instance field.
 481      * @exception ExceptionInInitializerError if the initialization provoked
 482      *              by this method fails.
 483      * @see       Field#get
 484      */
 485     public short getShort(Object obj)
 486         throws IllegalArgumentException, IllegalAccessException
 487     {
 488         return getFieldAccessor(obj).getShort(obj);
 489     }
 490 
 491     /**
 492      * Gets the value of a static or instance field of type
 493      * {@code int} or of another primitive type convertible to
 494      * type {@code int} via a widening conversion.
 495      *
 496      * @param obj the object to extract the {@code int} value
 497      * from
 498      * @return the value of the field converted to type {@code int}
 499      *
 500      * @exception IllegalAccessException    if the underlying field
 501      *              is inaccessible.

 502      * @exception IllegalArgumentException  if the specified object is not
 503      *              an instance of the class or interface declaring the
 504      *              underlying field (or a subclass or implementor
 505      *              thereof), or if the field value cannot be
 506      *              converted to the type {@code int} by a
 507      *              widening conversion.
 508      * @exception NullPointerException      if the specified object is null
 509      *              and the field is an instance field.
 510      * @exception ExceptionInInitializerError if the initialization provoked
 511      *              by this method fails.
 512      * @see       Field#get
 513      */
 514     public int getInt(Object obj)
 515         throws IllegalArgumentException, IllegalAccessException
 516     {
 517         return getFieldAccessor(obj).getInt(obj);
 518     }
 519 
 520     /**
 521      * Gets the value of a static or instance field of type
 522      * {@code long} or of another primitive type convertible to
 523      * type {@code long} via a widening conversion.
 524      *
 525      * @param obj the object to extract the {@code long} value
 526      * from
 527      * @return the value of the field converted to type {@code long}
 528      *
 529      * @exception IllegalAccessException    if the underlying field
 530      *              is inaccessible.

 531      * @exception IllegalArgumentException  if the specified object is not
 532      *              an instance of the class or interface declaring the
 533      *              underlying field (or a subclass or implementor
 534      *              thereof), or if the field value cannot be
 535      *              converted to the type {@code long} by a
 536      *              widening conversion.
 537      * @exception NullPointerException      if the specified object is null
 538      *              and the field is an instance field.
 539      * @exception ExceptionInInitializerError if the initialization provoked
 540      *              by this method fails.
 541      * @see       Field#get
 542      */
 543     public long getLong(Object obj)
 544         throws IllegalArgumentException, IllegalAccessException
 545     {
 546         return getFieldAccessor(obj).getLong(obj);
 547     }
 548 
 549     /**
 550      * Gets the value of a static or instance field of type
 551      * {@code float} or of another primitive type convertible to
 552      * type {@code float} via a widening conversion.
 553      *
 554      * @param obj the object to extract the {@code float} value
 555      * from
 556      * @return the value of the field converted to type {@code float}
 557      *
 558      * @exception IllegalAccessException    if the underlying field
 559      *              is inaccessible.

 560      * @exception IllegalArgumentException  if the specified object is not
 561      *              an instance of the class or interface declaring the
 562      *              underlying field (or a subclass or implementor
 563      *              thereof), or if the field value cannot be
 564      *              converted to the type {@code float} by a
 565      *              widening conversion.
 566      * @exception NullPointerException      if the specified object is null
 567      *              and the field is an instance field.
 568      * @exception ExceptionInInitializerError if the initialization provoked
 569      *              by this method fails.
 570      * @see Field#get
 571      */
 572     public float getFloat(Object obj)
 573         throws IllegalArgumentException, IllegalAccessException
 574     {
 575         return getFieldAccessor(obj).getFloat(obj);
 576     }
 577 
 578     /**
 579      * Gets the value of a static or instance field of type
 580      * {@code double} or of another primitive type convertible to
 581      * type {@code double} via a widening conversion.
 582      *
 583      * @param obj the object to extract the {@code double} value
 584      * from
 585      * @return the value of the field converted to type {@code double}
 586      *
 587      * @exception IllegalAccessException    if the underlying field
 588      *              is inaccessible.

 589      * @exception IllegalArgumentException  if the specified object is not
 590      *              an instance of the class or interface declaring the
 591      *              underlying field (or a subclass or implementor
 592      *              thereof), or if the field value cannot be
 593      *              converted to the type {@code double} by a
 594      *              widening conversion.
 595      * @exception NullPointerException      if the specified object is null
 596      *              and the field is an instance field.
 597      * @exception ExceptionInInitializerError if the initialization provoked
 598      *              by this method fails.
 599      * @see       Field#get
 600      */
 601     public double getDouble(Object obj)
 602         throws IllegalArgumentException, IllegalAccessException
 603     {
 604         return getFieldAccessor(obj).getDouble(obj);
 605     }
 606 
 607     /**
 608      * Sets the field represented by this {@code Field} object on the
 609      * specified object argument to the specified new value. The new
 610      * value is automatically unwrapped if the underlying field has a
 611      * primitive type.
 612      *
 613      * <p>The operation proceeds as follows:
 614      *
 615      * <p>If the underlying field is static, the {@code obj} argument is
 616      * ignored; it may be null.
 617      *
 618      * <p>Otherwise the underlying field is an instance field.  If the
 619      * specified object argument is null, the method throws a
 620      * {@code NullPointerException}.  If the specified object argument is not
 621      * an instance of the class or interface declaring the underlying
 622      * field, the method throws an {@code IllegalArgumentException}.
 623      *
 624      * <p>If this {@code Field} object enforces Java language access control, and
 625      * the underlying field is inaccessible, the method throws an
 626      * {@code IllegalAccessException}.
 627      *
 628      * <p>If the underlying field is final, the method throws an
 629      * {@code IllegalAccessException} unless
 630      * {@code setAccessible(true)} has succeeded for this field
 631      * and this field is non-static. Setting a final field in this way
 632      * is meaningful only during deserialization or reconstruction of
 633      * instances of classes with blank final fields, before they are
 634      * made available for access by other parts of a program. Use in
 635      * any other context may have unpredictable effects, including cases
 636      * in which other parts of a program continue to use the original
 637      * value of this field.
 638      *
 639      * <p>If the underlying field is of a primitive type, an unwrapping
 640      * conversion is attempted to convert the new value to a value of
 641      * a primitive type.  If this attempt fails, the method throws an
 642      * {@code IllegalArgumentException}.
 643      *
 644      * <p>If, after possible unwrapping, the new value cannot be
 645      * converted to the type of the underlying field by an identity or
 646      * widening conversion, the method throws an
 647      * {@code IllegalArgumentException}.
 648      *
 649      * <p>If the underlying field is static, the class that declared the
 650      * field is initialized if it has not already been initialized.
 651      *
 652      * <p>The field is set to the possibly unwrapped and widened new value.
 653      *
 654      * <p>If the field is hidden in the type of {@code obj},
 655      * the field's value is set according to the preceding rules.
 656      *
 657      * @param obj the object whose field should be modified
 658      * @param value the new value for the field of {@code obj}
 659      * being modified
 660      *
 661      * @exception IllegalAccessException    if the underlying field
 662      *              is inaccessible.

 663      * @exception IllegalArgumentException  if the specified object is not an
 664      *              instance of the class or interface declaring the underlying
 665      *              field (or a subclass or implementor thereof),
 666      *              or if an unwrapping conversion fails.
 667      * @exception NullPointerException      if the specified object is null
 668      *              and the field is an instance field.
 669      * @exception ExceptionInInitializerError if the initialization provoked
 670      *              by this method fails.
 671      */
 672     public void set(Object obj, Object value)
 673         throws IllegalArgumentException, IllegalAccessException
 674     {
 675         getFieldAccessor(obj).set(obj, value);
 676     }
 677 
 678     /**
 679      * Sets the value of a field as a {@code boolean} on the specified object.
 680      * This method is equivalent to
 681      * {@code set(obj, zObj)},
 682      * where {@code zObj} is a {@code Boolean} object and
 683      * {@code zObj.booleanValue() == z}.
 684      *
 685      * @param obj the object whose field should be modified
 686      * @param z   the new value for the field of {@code obj}
 687      * being modified
 688      *
 689      * @exception IllegalAccessException    if the underlying field
 690      *              is inaccessible.

 691      * @exception IllegalArgumentException  if the specified object is not an
 692      *              instance of the class or interface declaring the underlying
 693      *              field (or a subclass or implementor thereof),
 694      *              or if an unwrapping conversion fails.
 695      * @exception NullPointerException      if the specified object is null
 696      *              and the field is an instance field.
 697      * @exception ExceptionInInitializerError if the initialization provoked
 698      *              by this method fails.
 699      * @see       Field#set
 700      */
 701     public void setBoolean(Object obj, boolean z)
 702         throws IllegalArgumentException, IllegalAccessException
 703     {
 704         getFieldAccessor(obj).setBoolean(obj, z);
 705     }
 706 
 707     /**
 708      * Sets the value of a field as a {@code byte} on the specified object.
 709      * This method is equivalent to
 710      * {@code set(obj, bObj)},
 711      * where {@code bObj} is a {@code Byte} object and
 712      * {@code bObj.byteValue() == b}.
 713      *
 714      * @param obj the object whose field should be modified
 715      * @param b   the new value for the field of {@code obj}
 716      * being modified
 717      *
 718      * @exception IllegalAccessException    if the underlying field
 719      *              is inaccessible.

 720      * @exception IllegalArgumentException  if the specified object is not an
 721      *              instance of the class or interface declaring the underlying
 722      *              field (or a subclass or implementor thereof),
 723      *              or if an unwrapping conversion fails.
 724      * @exception NullPointerException      if the specified object is null
 725      *              and the field is an instance field.
 726      * @exception ExceptionInInitializerError if the initialization provoked
 727      *              by this method fails.
 728      * @see       Field#set
 729      */
 730     public void setByte(Object obj, byte b)
 731         throws IllegalArgumentException, IllegalAccessException
 732     {
 733         getFieldAccessor(obj).setByte(obj, b);
 734     }
 735 
 736     /**
 737      * Sets the value of a field as a {@code char} on the specified object.
 738      * This method is equivalent to
 739      * {@code set(obj, cObj)},
 740      * where {@code cObj} is a {@code Character} object and
 741      * {@code cObj.charValue() == c}.
 742      *
 743      * @param obj the object whose field should be modified
 744      * @param c   the new value for the field of {@code obj}
 745      * being modified
 746      *
 747      * @exception IllegalAccessException    if the underlying field
 748      *              is inaccessible.

 749      * @exception IllegalArgumentException  if the specified object is not an
 750      *              instance of the class or interface declaring the underlying
 751      *              field (or a subclass or implementor thereof),
 752      *              or if an unwrapping conversion fails.
 753      * @exception NullPointerException      if the specified object is null
 754      *              and the field is an instance field.
 755      * @exception ExceptionInInitializerError if the initialization provoked
 756      *              by this method fails.
 757      * @see       Field#set
 758      */
 759     public void setChar(Object obj, char c)
 760         throws IllegalArgumentException, IllegalAccessException
 761     {
 762         getFieldAccessor(obj).setChar(obj, c);
 763     }
 764 
 765     /**
 766      * Sets the value of a field as a {@code short} on the specified object.
 767      * This method is equivalent to
 768      * {@code set(obj, sObj)},
 769      * where {@code sObj} is a {@code Short} object and
 770      * {@code sObj.shortValue() == s}.
 771      *
 772      * @param obj the object whose field should be modified
 773      * @param s   the new value for the field of {@code obj}
 774      * being modified
 775      *
 776      * @exception IllegalAccessException    if the underlying field
 777      *              is inaccessible.

 778      * @exception IllegalArgumentException  if the specified object is not an
 779      *              instance of the class or interface declaring the underlying
 780      *              field (or a subclass or implementor thereof),
 781      *              or if an unwrapping conversion fails.
 782      * @exception NullPointerException      if the specified object is null
 783      *              and the field is an instance field.
 784      * @exception ExceptionInInitializerError if the initialization provoked
 785      *              by this method fails.
 786      * @see       Field#set
 787      */
 788     public void setShort(Object obj, short s)
 789         throws IllegalArgumentException, IllegalAccessException
 790     {
 791         getFieldAccessor(obj).setShort(obj, s);
 792     }
 793 
 794     /**
 795      * Sets the value of a field as an {@code int} on the specified object.
 796      * This method is equivalent to
 797      * {@code set(obj, iObj)},
 798      * where {@code iObj} is a {@code Integer} object and
 799      * {@code iObj.intValue() == i}.
 800      *
 801      * @param obj the object whose field should be modified
 802      * @param i   the new value for the field of {@code obj}
 803      * being modified
 804      *
 805      * @exception IllegalAccessException    if the underlying field
 806      *              is inaccessible.

 807      * @exception IllegalArgumentException  if the specified object is not an
 808      *              instance of the class or interface declaring the underlying
 809      *              field (or a subclass or implementor thereof),
 810      *              or if an unwrapping conversion fails.
 811      * @exception NullPointerException      if the specified object is null
 812      *              and the field is an instance field.
 813      * @exception ExceptionInInitializerError if the initialization provoked
 814      *              by this method fails.
 815      * @see       Field#set
 816      */
 817     public void setInt(Object obj, int i)
 818         throws IllegalArgumentException, IllegalAccessException
 819     {
 820         getFieldAccessor(obj).setInt(obj, i);
 821     }
 822 
 823     /**
 824      * Sets the value of a field as a {@code long} on the specified object.
 825      * This method is equivalent to
 826      * {@code set(obj, lObj)},
 827      * where {@code lObj} is a {@code Long} object and
 828      * {@code lObj.longValue() == l}.
 829      *
 830      * @param obj the object whose field should be modified
 831      * @param l   the new value for the field of {@code obj}
 832      * being modified
 833      *
 834      * @exception IllegalAccessException    if the underlying field
 835      *              is inaccessible.

 836      * @exception IllegalArgumentException  if the specified object is not an
 837      *              instance of the class or interface declaring the underlying
 838      *              field (or a subclass or implementor thereof),
 839      *              or if an unwrapping conversion fails.
 840      * @exception NullPointerException      if the specified object is null
 841      *              and the field is an instance field.
 842      * @exception ExceptionInInitializerError if the initialization provoked
 843      *              by this method fails.
 844      * @see       Field#set
 845      */
 846     public void setLong(Object obj, long l)
 847         throws IllegalArgumentException, IllegalAccessException
 848     {
 849         getFieldAccessor(obj).setLong(obj, l);
 850     }
 851 
 852     /**
 853      * Sets the value of a field as a {@code float} on the specified object.
 854      * This method is equivalent to
 855      * {@code set(obj, fObj)},
 856      * where {@code fObj} is a {@code Float} object and
 857      * {@code fObj.floatValue() == f}.
 858      *
 859      * @param obj the object whose field should be modified
 860      * @param f   the new value for the field of {@code obj}
 861      * being modified
 862      *
 863      * @exception IllegalAccessException    if the underlying field
 864      *              is inaccessible.

 865      * @exception IllegalArgumentException  if the specified object is not an
 866      *              instance of the class or interface declaring the underlying
 867      *              field (or a subclass or implementor thereof),
 868      *              or if an unwrapping conversion fails.
 869      * @exception NullPointerException      if the specified object is null
 870      *              and the field is an instance field.
 871      * @exception ExceptionInInitializerError if the initialization provoked
 872      *              by this method fails.
 873      * @see       Field#set
 874      */
 875     public void setFloat(Object obj, float f)
 876         throws IllegalArgumentException, IllegalAccessException
 877     {
 878         getFieldAccessor(obj).setFloat(obj, f);
 879     }
 880 
 881     /**
 882      * Sets the value of a field as a {@code double} on the specified object.
 883      * This method is equivalent to
 884      * {@code set(obj, dObj)},
 885      * where {@code dObj} is a {@code Double} object and
 886      * {@code dObj.doubleValue() == d}.
 887      *
 888      * @param obj the object whose field should be modified
 889      * @param d   the new value for the field of {@code obj}
 890      * being modified
 891      *
 892      * @exception IllegalAccessException    if the underlying field
 893      *              is inaccessible.

 894      * @exception IllegalArgumentException  if the specified object is not an
 895      *              instance of the class or interface declaring the underlying
 896      *              field (or a subclass or implementor thereof),
 897      *              or if an unwrapping conversion fails.
 898      * @exception NullPointerException      if the specified object is null
 899      *              and the field is an instance field.
 900      * @exception ExceptionInInitializerError if the initialization provoked
 901      *              by this method fails.
 902      * @see       Field#set
 903      */
 904     public void setDouble(Object obj, double d)
 905         throws IllegalArgumentException, IllegalAccessException
 906     {
 907         getFieldAccessor(obj).setDouble(obj, d);
 908     }
 909 
 910     // Convenience routine which performs security checks
 911     private FieldAccessor getFieldAccessor(Object obj)
 912         throws IllegalAccessException
 913     {




 343      * <p>If this {@code Field} object enforces Java language access control, and
 344      * the underlying field is inaccessible, the method throws an
 345      * {@code IllegalAccessException}.
 346      * If the underlying field is static, the class that declared the
 347      * field is initialized if it has not already been initialized.
 348      *
 349      * <p>Otherwise, the value is retrieved from the underlying instance
 350      * or static field.  If the field has a primitive type, the value
 351      * is wrapped in an object before being returned, otherwise it is
 352      * returned as is.
 353      *
 354      * <p>If the field is hidden in the type of {@code obj},
 355      * the field's value is obtained according to the preceding rules.
 356      *
 357      * @param obj object from which the represented field's value is
 358      * to be extracted
 359      * @return the value of the represented field in object
 360      * {@code obj}; primitive values are wrapped in an appropriate
 361      * object before being returned
 362      *
 363      * @exception IllegalAccessException    if this {@code Field} object
 364      *              enforces Java language access control and the underlying
 365      *              field is inaccessible.
 366      * @exception IllegalArgumentException  if the specified object is not an
 367      *              instance of the class or interface declaring the underlying
 368      *              field (or a subclass or implementor thereof).
 369      * @exception NullPointerException      if the specified object is null
 370      *              and the field is an instance field.
 371      * @exception ExceptionInInitializerError if the initialization provoked
 372      *              by this method fails.
 373      */
 374     public Object get(Object obj)
 375         throws IllegalArgumentException, IllegalAccessException
 376     {
 377         return getFieldAccessor(obj).get(obj);
 378     }
 379 
 380     /**
 381      * Gets the value of a static or instance {@code boolean} field.
 382      *
 383      * @param obj the object to extract the {@code boolean} value
 384      * from
 385      * @return the value of the {@code boolean} field
 386      *
 387      * @exception IllegalAccessException    if this {@code Field} object
 388      *              enforces Java language access control and the underlying
 389      *              field is inaccessible.
 390      * @exception IllegalArgumentException  if the specified object is not
 391      *              an instance of the class or interface declaring the
 392      *              underlying field (or a subclass or implementor
 393      *              thereof), or if the field value cannot be
 394      *              converted to the type {@code boolean} by a
 395      *              widening conversion.
 396      * @exception NullPointerException      if the specified object is null
 397      *              and the field is an instance field.
 398      * @exception ExceptionInInitializerError if the initialization provoked
 399      *              by this method fails.
 400      * @see       Field#get
 401      */
 402     public boolean getBoolean(Object obj)
 403         throws IllegalArgumentException, IllegalAccessException
 404     {
 405         return getFieldAccessor(obj).getBoolean(obj);
 406     }
 407 
 408     /**
 409      * Gets the value of a static or instance {@code byte} field.
 410      *
 411      * @param obj the object to extract the {@code byte} value
 412      * from
 413      * @return the value of the {@code byte} field
 414      *
 415      * @exception IllegalAccessException    if this {@code Field} object
 416      *              enforces Java language access control and the underlying
 417      *              field is inaccessible.
 418      * @exception IllegalArgumentException  if the specified object is not
 419      *              an instance of the class or interface declaring the
 420      *              underlying field (or a subclass or implementor
 421      *              thereof), or if the field value cannot be
 422      *              converted to the type {@code byte} by a
 423      *              widening conversion.
 424      * @exception NullPointerException      if the specified object is null
 425      *              and the field is an instance field.
 426      * @exception ExceptionInInitializerError if the initialization provoked
 427      *              by this method fails.
 428      * @see       Field#get
 429      */
 430     public byte getByte(Object obj)
 431         throws IllegalArgumentException, IllegalAccessException
 432     {
 433         return getFieldAccessor(obj).getByte(obj);
 434     }
 435 
 436     /**
 437      * Gets the value of a static or instance field of type
 438      * {@code char} or of another primitive type convertible to
 439      * type {@code char} via a widening conversion.
 440      *
 441      * @param obj the object to extract the {@code char} value
 442      * from
 443      * @return the value of the field converted to type {@code char}
 444      *
 445      * @exception IllegalAccessException    if this {@code Field} object
 446      *              enforces Java language access control and the underlying
 447      *              field is inaccessible.
 448      * @exception IllegalArgumentException  if the specified object is not
 449      *              an instance of the class or interface declaring the
 450      *              underlying field (or a subclass or implementor
 451      *              thereof), or if the field value cannot be
 452      *              converted to the type {@code char} by a
 453      *              widening conversion.
 454      * @exception NullPointerException      if the specified object is null
 455      *              and the field is an instance field.
 456      * @exception ExceptionInInitializerError if the initialization provoked
 457      *              by this method fails.
 458      * @see Field#get
 459      */
 460     public char getChar(Object obj)
 461         throws IllegalArgumentException, IllegalAccessException
 462     {
 463         return getFieldAccessor(obj).getChar(obj);
 464     }
 465 
 466     /**
 467      * Gets the value of a static or instance field of type
 468      * {@code short} or of another primitive type convertible to
 469      * type {@code short} via a widening conversion.
 470      *
 471      * @param obj the object to extract the {@code short} value
 472      * from
 473      * @return the value of the field converted to type {@code short}
 474      *
 475      * @exception IllegalAccessException    if this {@code Field} object
 476      *              enforces Java language access control and the underlying
 477      *              field is inaccessible.
 478      * @exception IllegalArgumentException  if the specified object is not
 479      *              an instance of the class or interface declaring the
 480      *              underlying field (or a subclass or implementor
 481      *              thereof), or if the field value cannot be
 482      *              converted to the type {@code short} by a
 483      *              widening conversion.
 484      * @exception NullPointerException      if the specified object is null
 485      *              and the field is an instance field.
 486      * @exception ExceptionInInitializerError if the initialization provoked
 487      *              by this method fails.
 488      * @see       Field#get
 489      */
 490     public short getShort(Object obj)
 491         throws IllegalArgumentException, IllegalAccessException
 492     {
 493         return getFieldAccessor(obj).getShort(obj);
 494     }
 495 
 496     /**
 497      * Gets the value of a static or instance field of type
 498      * {@code int} or of another primitive type convertible to
 499      * type {@code int} via a widening conversion.
 500      *
 501      * @param obj the object to extract the {@code int} value
 502      * from
 503      * @return the value of the field converted to type {@code int}
 504      *
 505      * @exception IllegalAccessException    if this {@code Field} object
 506      *              enforces Java language access control and the underlying
 507      *              field is inaccessible.
 508      * @exception IllegalArgumentException  if the specified object is not
 509      *              an instance of the class or interface declaring the
 510      *              underlying field (or a subclass or implementor
 511      *              thereof), or if the field value cannot be
 512      *              converted to the type {@code int} by a
 513      *              widening conversion.
 514      * @exception NullPointerException      if the specified object is null
 515      *              and the field is an instance field.
 516      * @exception ExceptionInInitializerError if the initialization provoked
 517      *              by this method fails.
 518      * @see       Field#get
 519      */
 520     public int getInt(Object obj)
 521         throws IllegalArgumentException, IllegalAccessException
 522     {
 523         return getFieldAccessor(obj).getInt(obj);
 524     }
 525 
 526     /**
 527      * Gets the value of a static or instance field of type
 528      * {@code long} or of another primitive type convertible to
 529      * type {@code long} via a widening conversion.
 530      *
 531      * @param obj the object to extract the {@code long} value
 532      * from
 533      * @return the value of the field converted to type {@code long}
 534      *
 535      * @exception IllegalAccessException    if this {@code Field} object
 536      *              enforces Java language access control and the underlying
 537      *              field is inaccessible.
 538      * @exception IllegalArgumentException  if the specified object is not
 539      *              an instance of the class or interface declaring the
 540      *              underlying field (or a subclass or implementor
 541      *              thereof), or if the field value cannot be
 542      *              converted to the type {@code long} by a
 543      *              widening conversion.
 544      * @exception NullPointerException      if the specified object is null
 545      *              and the field is an instance field.
 546      * @exception ExceptionInInitializerError if the initialization provoked
 547      *              by this method fails.
 548      * @see       Field#get
 549      */
 550     public long getLong(Object obj)
 551         throws IllegalArgumentException, IllegalAccessException
 552     {
 553         return getFieldAccessor(obj).getLong(obj);
 554     }
 555 
 556     /**
 557      * Gets the value of a static or instance field of type
 558      * {@code float} or of another primitive type convertible to
 559      * type {@code float} via a widening conversion.
 560      *
 561      * @param obj the object to extract the {@code float} value
 562      * from
 563      * @return the value of the field converted to type {@code float}
 564      *
 565      * @exception IllegalAccessException    if this {@code Field} object
 566      *              enforces Java language access control and the underlying
 567      *              field is inaccessible.
 568      * @exception IllegalArgumentException  if the specified object is not
 569      *              an instance of the class or interface declaring the
 570      *              underlying field (or a subclass or implementor
 571      *              thereof), or if the field value cannot be
 572      *              converted to the type {@code float} by a
 573      *              widening conversion.
 574      * @exception NullPointerException      if the specified object is null
 575      *              and the field is an instance field.
 576      * @exception ExceptionInInitializerError if the initialization provoked
 577      *              by this method fails.
 578      * @see Field#get
 579      */
 580     public float getFloat(Object obj)
 581         throws IllegalArgumentException, IllegalAccessException
 582     {
 583         return getFieldAccessor(obj).getFloat(obj);
 584     }
 585 
 586     /**
 587      * Gets the value of a static or instance field of type
 588      * {@code double} or of another primitive type convertible to
 589      * type {@code double} via a widening conversion.
 590      *
 591      * @param obj the object to extract the {@code double} value
 592      * from
 593      * @return the value of the field converted to type {@code double}
 594      *
 595      * @exception IllegalAccessException    if this {@code Field} object
 596      *              enforces Java language access control and the underlying
 597      *              field is inaccessible.
 598      * @exception IllegalArgumentException  if the specified object is not
 599      *              an instance of the class or interface declaring the
 600      *              underlying field (or a subclass or implementor
 601      *              thereof), or if the field value cannot be
 602      *              converted to the type {@code double} by a
 603      *              widening conversion.
 604      * @exception NullPointerException      if the specified object is null
 605      *              and the field is an instance field.
 606      * @exception ExceptionInInitializerError if the initialization provoked
 607      *              by this method fails.
 608      * @see       Field#get
 609      */
 610     public double getDouble(Object obj)
 611         throws IllegalArgumentException, IllegalAccessException
 612     {
 613         return getFieldAccessor(obj).getDouble(obj);
 614     }
 615 
 616     /**
 617      * Sets the field represented by this {@code Field} object on the
 618      * specified object argument to the specified new value. The new
 619      * value is automatically unwrapped if the underlying field has a
 620      * primitive type.
 621      *
 622      * <p>The operation proceeds as follows:
 623      *
 624      * <p>If the underlying field is static, the {@code obj} argument is
 625      * ignored; it may be null.
 626      *
 627      * <p>Otherwise the underlying field is an instance field.  If the
 628      * specified object argument is null, the method throws a
 629      * {@code NullPointerException}.  If the specified object argument is not
 630      * an instance of the class or interface declaring the underlying
 631      * field, the method throws an {@code IllegalArgumentException}.
 632      *
 633      * <p>If this {@code Field} object enforces Java language access control, and
 634      * the underlying field is inaccessible, the method throws an
 635      * {@code IllegalAccessException}.
 636      *
 637      * <p>If the underlying field is final, the method throws an
 638      * {@code IllegalAccessException} unless {@code setAccessible(true)}
 639      * has succeeded for this {@code Field} object
 640      * and the field is non-static. Setting a final field in this way
 641      * is meaningful only during deserialization or reconstruction of
 642      * instances of classes with blank final fields, before they are
 643      * made available for access by other parts of a program. Use in
 644      * any other context may have unpredictable effects, including cases
 645      * in which other parts of a program continue to use the original
 646      * value of this field.
 647      *
 648      * <p>If the underlying field is of a primitive type, an unwrapping
 649      * conversion is attempted to convert the new value to a value of
 650      * a primitive type.  If this attempt fails, the method throws an
 651      * {@code IllegalArgumentException}.
 652      *
 653      * <p>If, after possible unwrapping, the new value cannot be
 654      * converted to the type of the underlying field by an identity or
 655      * widening conversion, the method throws an
 656      * {@code IllegalArgumentException}.
 657      *
 658      * <p>If the underlying field is static, the class that declared the
 659      * field is initialized if it has not already been initialized.
 660      *
 661      * <p>The field is set to the possibly unwrapped and widened new value.
 662      *
 663      * <p>If the field is hidden in the type of {@code obj},
 664      * the field's value is set according to the preceding rules.
 665      *
 666      * @param obj the object whose field should be modified
 667      * @param value the new value for the field of {@code obj}
 668      * being modified
 669      *
 670      * @exception IllegalAccessException    if this {@code Field} object
 671      *              enforces Java language access control and the underlying
 672      *              field is either inaccessible or final.
 673      * @exception IllegalArgumentException  if the specified object is not an
 674      *              instance of the class or interface declaring the underlying
 675      *              field (or a subclass or implementor thereof),
 676      *              or if an unwrapping conversion fails.
 677      * @exception NullPointerException      if the specified object is null
 678      *              and the field is an instance field.
 679      * @exception ExceptionInInitializerError if the initialization provoked
 680      *              by this method fails.
 681      */
 682     public void set(Object obj, Object value)
 683         throws IllegalArgumentException, IllegalAccessException
 684     {
 685         getFieldAccessor(obj).set(obj, value);
 686     }
 687 
 688     /**
 689      * Sets the value of a field as a {@code boolean} on the specified object.
 690      * This method is equivalent to
 691      * {@code set(obj, zObj)},
 692      * where {@code zObj} is a {@code Boolean} object and
 693      * {@code zObj.booleanValue() == z}.
 694      *
 695      * @param obj the object whose field should be modified
 696      * @param z   the new value for the field of {@code obj}
 697      * being modified
 698      *
 699      * @exception IllegalAccessException    if this {@code Field} object
 700      *              enforces Java language access control and the underlying
 701      *              field is either inaccessible or final.
 702      * @exception IllegalArgumentException  if the specified object is not an
 703      *              instance of the class or interface declaring the underlying
 704      *              field (or a subclass or implementor thereof),
 705      *              or if an unwrapping conversion fails.
 706      * @exception NullPointerException      if the specified object is null
 707      *              and the field is an instance field.
 708      * @exception ExceptionInInitializerError if the initialization provoked
 709      *              by this method fails.
 710      * @see       Field#set
 711      */
 712     public void setBoolean(Object obj, boolean z)
 713         throws IllegalArgumentException, IllegalAccessException
 714     {
 715         getFieldAccessor(obj).setBoolean(obj, z);
 716     }
 717 
 718     /**
 719      * Sets the value of a field as a {@code byte} on the specified object.
 720      * This method is equivalent to
 721      * {@code set(obj, bObj)},
 722      * where {@code bObj} is a {@code Byte} object and
 723      * {@code bObj.byteValue() == b}.
 724      *
 725      * @param obj the object whose field should be modified
 726      * @param b   the new value for the field of {@code obj}
 727      * being modified
 728      *
 729      * @exception IllegalAccessException    if this {@code Field} object
 730      *              enforces Java language access control and the underlying
 731      *              field is either inaccessible or final.
 732      * @exception IllegalArgumentException  if the specified object is not an
 733      *              instance of the class or interface declaring the underlying
 734      *              field (or a subclass or implementor thereof),
 735      *              or if an unwrapping conversion fails.
 736      * @exception NullPointerException      if the specified object is null
 737      *              and the field is an instance field.
 738      * @exception ExceptionInInitializerError if the initialization provoked
 739      *              by this method fails.
 740      * @see       Field#set
 741      */
 742     public void setByte(Object obj, byte b)
 743         throws IllegalArgumentException, IllegalAccessException
 744     {
 745         getFieldAccessor(obj).setByte(obj, b);
 746     }
 747 
 748     /**
 749      * Sets the value of a field as a {@code char} on the specified object.
 750      * This method is equivalent to
 751      * {@code set(obj, cObj)},
 752      * where {@code cObj} is a {@code Character} object and
 753      * {@code cObj.charValue() == c}.
 754      *
 755      * @param obj the object whose field should be modified
 756      * @param c   the new value for the field of {@code obj}
 757      * being modified
 758      *
 759      * @exception IllegalAccessException    if this {@code Field} object
 760      *              enforces Java language access control and the underlying
 761      *              field is either inaccessible or final.
 762      * @exception IllegalArgumentException  if the specified object is not an
 763      *              instance of the class or interface declaring the underlying
 764      *              field (or a subclass or implementor thereof),
 765      *              or if an unwrapping conversion fails.
 766      * @exception NullPointerException      if the specified object is null
 767      *              and the field is an instance field.
 768      * @exception ExceptionInInitializerError if the initialization provoked
 769      *              by this method fails.
 770      * @see       Field#set
 771      */
 772     public void setChar(Object obj, char c)
 773         throws IllegalArgumentException, IllegalAccessException
 774     {
 775         getFieldAccessor(obj).setChar(obj, c);
 776     }
 777 
 778     /**
 779      * Sets the value of a field as a {@code short} on the specified object.
 780      * This method is equivalent to
 781      * {@code set(obj, sObj)},
 782      * where {@code sObj} is a {@code Short} object and
 783      * {@code sObj.shortValue() == s}.
 784      *
 785      * @param obj the object whose field should be modified
 786      * @param s   the new value for the field of {@code obj}
 787      * being modified
 788      *
 789      * @exception IllegalAccessException    if this {@code Field} object
 790      *              enforces Java language access control and the underlying
 791      *              field is either inaccessible or final.
 792      * @exception IllegalArgumentException  if the specified object is not an
 793      *              instance of the class or interface declaring the underlying
 794      *              field (or a subclass or implementor thereof),
 795      *              or if an unwrapping conversion fails.
 796      * @exception NullPointerException      if the specified object is null
 797      *              and the field is an instance field.
 798      * @exception ExceptionInInitializerError if the initialization provoked
 799      *              by this method fails.
 800      * @see       Field#set
 801      */
 802     public void setShort(Object obj, short s)
 803         throws IllegalArgumentException, IllegalAccessException
 804     {
 805         getFieldAccessor(obj).setShort(obj, s);
 806     }
 807 
 808     /**
 809      * Sets the value of a field as an {@code int} on the specified object.
 810      * This method is equivalent to
 811      * {@code set(obj, iObj)},
 812      * where {@code iObj} is a {@code Integer} object and
 813      * {@code iObj.intValue() == i}.
 814      *
 815      * @param obj the object whose field should be modified
 816      * @param i   the new value for the field of {@code obj}
 817      * being modified
 818      *
 819      * @exception IllegalAccessException    if this {@code Field} object
 820      *              enforces Java language access control and the underlying
 821      *              field is either inaccessible or final.
 822      * @exception IllegalArgumentException  if the specified object is not an
 823      *              instance of the class or interface declaring the underlying
 824      *              field (or a subclass or implementor thereof),
 825      *              or if an unwrapping conversion fails.
 826      * @exception NullPointerException      if the specified object is null
 827      *              and the field is an instance field.
 828      * @exception ExceptionInInitializerError if the initialization provoked
 829      *              by this method fails.
 830      * @see       Field#set
 831      */
 832     public void setInt(Object obj, int i)
 833         throws IllegalArgumentException, IllegalAccessException
 834     {
 835         getFieldAccessor(obj).setInt(obj, i);
 836     }
 837 
 838     /**
 839      * Sets the value of a field as a {@code long} on the specified object.
 840      * This method is equivalent to
 841      * {@code set(obj, lObj)},
 842      * where {@code lObj} is a {@code Long} object and
 843      * {@code lObj.longValue() == l}.
 844      *
 845      * @param obj the object whose field should be modified
 846      * @param l   the new value for the field of {@code obj}
 847      * being modified
 848      *
 849      * @exception IllegalAccessException    if this {@code Field} object
 850      *              enforces Java language access control and the underlying
 851      *              field is either inaccessible or final.
 852      * @exception IllegalArgumentException  if the specified object is not an
 853      *              instance of the class or interface declaring the underlying
 854      *              field (or a subclass or implementor thereof),
 855      *              or if an unwrapping conversion fails.
 856      * @exception NullPointerException      if the specified object is null
 857      *              and the field is an instance field.
 858      * @exception ExceptionInInitializerError if the initialization provoked
 859      *              by this method fails.
 860      * @see       Field#set
 861      */
 862     public void setLong(Object obj, long l)
 863         throws IllegalArgumentException, IllegalAccessException
 864     {
 865         getFieldAccessor(obj).setLong(obj, l);
 866     }
 867 
 868     /**
 869      * Sets the value of a field as a {@code float} on the specified object.
 870      * This method is equivalent to
 871      * {@code set(obj, fObj)},
 872      * where {@code fObj} is a {@code Float} object and
 873      * {@code fObj.floatValue() == f}.
 874      *
 875      * @param obj the object whose field should be modified
 876      * @param f   the new value for the field of {@code obj}
 877      * being modified
 878      *
 879      * @exception IllegalAccessException    if this {@code Field} object
 880      *              enforces Java language access control and the underlying
 881      *              field is either inaccessible or final.
 882      * @exception IllegalArgumentException  if the specified object is not an
 883      *              instance of the class or interface declaring the underlying
 884      *              field (or a subclass or implementor thereof),
 885      *              or if an unwrapping conversion fails.
 886      * @exception NullPointerException      if the specified object is null
 887      *              and the field is an instance field.
 888      * @exception ExceptionInInitializerError if the initialization provoked
 889      *              by this method fails.
 890      * @see       Field#set
 891      */
 892     public void setFloat(Object obj, float f)
 893         throws IllegalArgumentException, IllegalAccessException
 894     {
 895         getFieldAccessor(obj).setFloat(obj, f);
 896     }
 897 
 898     /**
 899      * Sets the value of a field as a {@code double} on the specified object.
 900      * This method is equivalent to
 901      * {@code set(obj, dObj)},
 902      * where {@code dObj} is a {@code Double} object and
 903      * {@code dObj.doubleValue() == d}.
 904      *
 905      * @param obj the object whose field should be modified
 906      * @param d   the new value for the field of {@code obj}
 907      * being modified
 908      *
 909      * @exception IllegalAccessException    if this {@code Field} object
 910      *              enforces Java language access control and the underlying
 911      *              field is either inaccessible or final.
 912      * @exception IllegalArgumentException  if the specified object is not an
 913      *              instance of the class or interface declaring the underlying
 914      *              field (or a subclass or implementor thereof),
 915      *              or if an unwrapping conversion fails.
 916      * @exception NullPointerException      if the specified object is null
 917      *              and the field is an instance field.
 918      * @exception ExceptionInInitializerError if the initialization provoked
 919      *              by this method fails.
 920      * @see       Field#set
 921      */
 922     public void setDouble(Object obj, double d)
 923         throws IllegalArgumentException, IllegalAccessException
 924     {
 925         getFieldAccessor(obj).setDouble(obj, d);
 926     }
 927 
 928     // Convenience routine which performs security checks
 929     private FieldAccessor getFieldAccessor(Object obj)
 930         throws IllegalAccessException
 931     {