376 * <p>If this {@code Field} object is enforcing Java language access control, and
377 * the underlying field is inaccessible, the method throws an
378 * {@code IllegalAccessException}.
379 * If the underlying field is static, the class that declared the
380 * field is initialized if it has not already been initialized.
381 *
382 * <p>Otherwise, the value is retrieved from the underlying instance
383 * or static field. If the field has a primitive type, the value
384 * is wrapped in an object before being returned, otherwise it is
385 * returned as is.
386 *
387 * <p>If the field is hidden in the type of {@code obj},
388 * the field's value is obtained according to the preceding rules.
389 *
390 * @param obj object from which the represented field's value is
391 * to be extracted
392 * @return the value of the represented field in object
393 * {@code obj}; primitive values are wrapped in an appropriate
394 * object before being returned
395 *
396 * @exception IllegalAccessException if this {@code Field} object
397 * is enforcing Java language access control and the underlying
398 * field is inaccessible.
399 * @exception IllegalArgumentException if the specified object is not an
400 * instance of the class or interface declaring the underlying
401 * field (or a subclass or implementor thereof).
402 * @exception NullPointerException if the specified object is null
403 * and the field is an instance field.
404 * @exception ExceptionInInitializerError if the initialization provoked
405 * by this method fails.
406 */
407 @CallerSensitive
408 @ForceInline // to ensure Reflection.getCallerClass optimization
409 public Object get(Object obj)
410 throws IllegalArgumentException, IllegalAccessException
411 {
412 if (!override) {
413 Class<?> caller = Reflection.getCallerClass();
414 checkAccess(caller, obj);
415 }
416 return getFieldAccessor(obj).get(obj);
417 }
418
419 /**
420 * Gets the value of a static or instance {@code boolean} field.
421 *
422 * @param obj the object to extract the {@code boolean} value
423 * from
424 * @return the value of the {@code boolean} field
425 *
426 * @exception IllegalAccessException if this {@code Field} object
427 * is enforcing Java language access control and the underlying
428 * field is inaccessible.
429 * @exception IllegalArgumentException if the specified object is not
430 * an instance of the class or interface declaring the
431 * underlying field (or a subclass or implementor
432 * thereof), or if the field value cannot be
433 * converted to the type {@code boolean} by a
434 * widening conversion.
435 * @exception NullPointerException if the specified object is null
436 * and the field is an instance field.
437 * @exception ExceptionInInitializerError if the initialization provoked
438 * by this method fails.
439 * @see Field#get
440 */
441 @CallerSensitive
442 @ForceInline // to ensure Reflection.getCallerClass optimization
443 public boolean getBoolean(Object obj)
444 throws IllegalArgumentException, IllegalAccessException
445 {
446 if (!override) {
447 Class<?> caller = Reflection.getCallerClass();
448 checkAccess(caller, obj);
449 }
450 return getFieldAccessor(obj).getBoolean(obj);
451 }
452
453 /**
454 * Gets the value of a static or instance {@code byte} field.
455 *
456 * @param obj the object to extract the {@code byte} value
457 * from
458 * @return the value of the {@code byte} field
459 *
460 * @exception IllegalAccessException if this {@code Field} object
461 * is enforcing Java language access control and the underlying
462 * field is inaccessible.
463 * @exception IllegalArgumentException if the specified object is not
464 * an instance of the class or interface declaring the
465 * underlying field (or a subclass or implementor
466 * thereof), or if the field value cannot be
467 * converted to the type {@code byte} by a
468 * widening conversion.
469 * @exception NullPointerException if the specified object is null
470 * and the field is an instance field.
471 * @exception ExceptionInInitializerError if the initialization provoked
472 * by this method fails.
473 * @see Field#get
474 */
475 @CallerSensitive
476 @ForceInline // to ensure Reflection.getCallerClass optimization
477 public byte getByte(Object obj)
478 throws IllegalArgumentException, IllegalAccessException
479 {
480 if (!override) {
481 Class<?> caller = Reflection.getCallerClass();
482 checkAccess(caller, obj);
483 }
484 return getFieldAccessor(obj).getByte(obj);
485 }
486
487 /**
488 * Gets the value of a static or instance field of type
489 * {@code char} or of another primitive type convertible to
490 * type {@code char} via a widening conversion.
491 *
492 * @param obj the object to extract the {@code char} value
493 * from
494 * @return the value of the field converted to type {@code char}
495 *
496 * @exception IllegalAccessException if this {@code Field} object
497 * is enforcing Java language access control and the underlying
498 * field is inaccessible.
499 * @exception IllegalArgumentException if the specified object is not
500 * an instance of the class or interface declaring the
501 * underlying field (or a subclass or implementor
502 * thereof), or if the field value cannot be
503 * converted to the type {@code char} by a
504 * widening conversion.
505 * @exception NullPointerException if the specified object is null
506 * and the field is an instance field.
507 * @exception ExceptionInInitializerError if the initialization provoked
508 * by this method fails.
509 * @see Field#get
510 */
511 @CallerSensitive
512 @ForceInline // to ensure Reflection.getCallerClass optimization
513 public char getChar(Object obj)
514 throws IllegalArgumentException, IllegalAccessException
515 {
516 if (!override) {
517 Class<?> caller = Reflection.getCallerClass();
518 checkAccess(caller, obj);
519 }
520 return getFieldAccessor(obj).getChar(obj);
521 }
522
523 /**
524 * Gets the value of a static or instance field of type
525 * {@code short} or of another primitive type convertible to
526 * type {@code short} via a widening conversion.
527 *
528 * @param obj the object to extract the {@code short} value
529 * from
530 * @return the value of the field converted to type {@code short}
531 *
532 * @exception IllegalAccessException if this {@code Field} object
533 * is enforcing Java language access control and the underlying
534 * field is inaccessible.
535 * @exception IllegalArgumentException if the specified object is not
536 * an instance of the class or interface declaring the
537 * underlying field (or a subclass or implementor
538 * thereof), or if the field value cannot be
539 * converted to the type {@code short} by a
540 * widening conversion.
541 * @exception NullPointerException if the specified object is null
542 * and the field is an instance field.
543 * @exception ExceptionInInitializerError if the initialization provoked
544 * by this method fails.
545 * @see Field#get
546 */
547 @CallerSensitive
548 @ForceInline // to ensure Reflection.getCallerClass optimization
549 public short getShort(Object obj)
550 throws IllegalArgumentException, IllegalAccessException
551 {
552 if (!override) {
553 Class<?> caller = Reflection.getCallerClass();
554 checkAccess(caller, obj);
555 }
556 return getFieldAccessor(obj).getShort(obj);
557 }
558
559 /**
560 * Gets the value of a static or instance field of type
561 * {@code int} or of another primitive type convertible to
562 * type {@code int} via a widening conversion.
563 *
564 * @param obj the object to extract the {@code int} value
565 * from
566 * @return the value of the field converted to type {@code int}
567 *
568 * @exception IllegalAccessException if this {@code Field} object
569 * is enforcing Java language access control and the underlying
570 * field is inaccessible.
571 * @exception IllegalArgumentException if the specified object is not
572 * an instance of the class or interface declaring the
573 * underlying field (or a subclass or implementor
574 * thereof), or if the field value cannot be
575 * converted to the type {@code int} by a
576 * widening conversion.
577 * @exception NullPointerException if the specified object is null
578 * and the field is an instance field.
579 * @exception ExceptionInInitializerError if the initialization provoked
580 * by this method fails.
581 * @see Field#get
582 */
583 @CallerSensitive
584 @ForceInline // to ensure Reflection.getCallerClass optimization
585 public int getInt(Object obj)
586 throws IllegalArgumentException, IllegalAccessException
587 {
588 if (!override) {
589 Class<?> caller = Reflection.getCallerClass();
590 checkAccess(caller, obj);
591 }
592 return getFieldAccessor(obj).getInt(obj);
593 }
594
595 /**
596 * Gets the value of a static or instance field of type
597 * {@code long} or of another primitive type convertible to
598 * type {@code long} via a widening conversion.
599 *
600 * @param obj the object to extract the {@code long} value
601 * from
602 * @return the value of the field converted to type {@code long}
603 *
604 * @exception IllegalAccessException if this {@code Field} object
605 * is enforcing Java language access control and the underlying
606 * field is inaccessible.
607 * @exception IllegalArgumentException if the specified object is not
608 * an instance of the class or interface declaring the
609 * underlying field (or a subclass or implementor
610 * thereof), or if the field value cannot be
611 * converted to the type {@code long} by a
612 * widening conversion.
613 * @exception NullPointerException if the specified object is null
614 * and the field is an instance field.
615 * @exception ExceptionInInitializerError if the initialization provoked
616 * by this method fails.
617 * @see Field#get
618 */
619 @CallerSensitive
620 @ForceInline // to ensure Reflection.getCallerClass optimization
621 public long getLong(Object obj)
622 throws IllegalArgumentException, IllegalAccessException
623 {
624 if (!override) {
625 Class<?> caller = Reflection.getCallerClass();
626 checkAccess(caller, obj);
627 }
628 return getFieldAccessor(obj).getLong(obj);
629 }
630
631 /**
632 * Gets the value of a static or instance field of type
633 * {@code float} or of another primitive type convertible to
634 * type {@code float} via a widening conversion.
635 *
636 * @param obj the object to extract the {@code float} value
637 * from
638 * @return the value of the field converted to type {@code float}
639 *
640 * @exception IllegalAccessException if this {@code Field} object
641 * is enforcing Java language access control and the underlying
642 * field is inaccessible.
643 * @exception IllegalArgumentException if the specified object is not
644 * an instance of the class or interface declaring the
645 * underlying field (or a subclass or implementor
646 * thereof), or if the field value cannot be
647 * converted to the type {@code float} by a
648 * widening conversion.
649 * @exception NullPointerException if the specified object is null
650 * and the field is an instance field.
651 * @exception ExceptionInInitializerError if the initialization provoked
652 * by this method fails.
653 * @see Field#get
654 */
655 @CallerSensitive
656 @ForceInline // to ensure Reflection.getCallerClass optimization
657 public float getFloat(Object obj)
658 throws IllegalArgumentException, IllegalAccessException
659 {
660 if (!override) {
661 Class<?> caller = Reflection.getCallerClass();
662 checkAccess(caller, obj);
663 }
664 return getFieldAccessor(obj).getFloat(obj);
665 }
666
667 /**
668 * Gets the value of a static or instance field of type
669 * {@code double} or of another primitive type convertible to
670 * type {@code double} via a widening conversion.
671 *
672 * @param obj the object to extract the {@code double} value
673 * from
674 * @return the value of the field converted to type {@code double}
675 *
676 * @exception IllegalAccessException if this {@code Field} object
677 * is enforcing Java language access control and the underlying
678 * field is inaccessible.
679 * @exception IllegalArgumentException if the specified object is not
680 * an instance of the class or interface declaring the
681 * underlying field (or a subclass or implementor
682 * thereof), or if the field value cannot be
683 * converted to the type {@code double} by a
684 * widening conversion.
685 * @exception NullPointerException if the specified object is null
686 * and the field is an instance field.
687 * @exception ExceptionInInitializerError if the initialization provoked
688 * by this method fails.
689 * @see Field#get
690 */
691 @CallerSensitive
692 @ForceInline // to ensure Reflection.getCallerClass optimization
693 public double getDouble(Object obj)
694 throws IllegalArgumentException, IllegalAccessException
695 {
696 if (!override) {
697 Class<?> caller = Reflection.getCallerClass();
698 checkAccess(caller, obj);
699 }
700 return getFieldAccessor(obj).getDouble(obj);
701 }
702
703 /**
704 * Sets the field represented by this {@code Field} object on the
705 * specified object argument to the specified new value. The new
706 * value is automatically unwrapped if the underlying field has a
707 * primitive type.
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 *
748 * <p>The field is set to the possibly unwrapped and widened new value.
749 *
750 * <p>If the field is hidden in the type of {@code obj},
751 * the field's value is set according to the preceding rules.
752 *
753 * @param obj the object whose field should be modified
754 * @param value the new value for the field of {@code obj}
755 * being modified
756 *
757 * @exception IllegalAccessException if this {@code Field} object
758 * is enforcing Java language access control and the underlying
759 * field is either inaccessible or final.
760 * @exception IllegalArgumentException if the specified object is not an
761 * instance of the class or interface declaring the underlying
762 * field (or a subclass or implementor thereof),
763 * or if an unwrapping conversion fails.
764 * @exception NullPointerException if the specified object is null
765 * and the field is an instance field.
766 * @exception ExceptionInInitializerError if the initialization provoked
767 * by this method fails.
768 */
769 @CallerSensitive
770 @ForceInline // to ensure Reflection.getCallerClass optimization
771 public void set(Object obj, Object value)
772 throws IllegalArgumentException, IllegalAccessException
773 {
774 if (!override) {
775 Class<?> caller = Reflection.getCallerClass();
776 checkAccess(caller, obj);
777 }
778 getFieldAccessor(obj).set(obj, value);
779 }
780
781 /**
782 * Sets the value of a field as a {@code boolean} on the specified object.
783 * This method is equivalent to
784 * {@code set(obj, zObj)},
785 * where {@code zObj} is a {@code Boolean} object and
786 * {@code zObj.booleanValue() == z}.
787 *
788 * @param obj the object whose field should be modified
789 * @param z the new value for the field of {@code obj}
790 * being modified
791 *
792 * @exception IllegalAccessException if this {@code Field} object
793 * is enforcing Java language access control and the underlying
794 * field is either inaccessible or final.
795 * @exception IllegalArgumentException if the specified object is not an
796 * instance of the class or interface declaring the underlying
797 * field (or a subclass or implementor thereof),
798 * or if an unwrapping conversion fails.
799 * @exception NullPointerException if the specified object is null
800 * and the field is an instance field.
801 * @exception ExceptionInInitializerError if the initialization provoked
802 * by this method fails.
803 * @see Field#set
804 */
805 @CallerSensitive
806 @ForceInline // to ensure Reflection.getCallerClass optimization
807 public void setBoolean(Object obj, boolean z)
808 throws IllegalArgumentException, IllegalAccessException
809 {
810 if (!override) {
811 Class<?> caller = Reflection.getCallerClass();
812 checkAccess(caller, obj);
813 }
814 getFieldAccessor(obj).setBoolean(obj, z);
815 }
816
817 /**
818 * Sets the value of a field as a {@code byte} on the specified object.
819 * This method is equivalent to
820 * {@code set(obj, bObj)},
821 * where {@code bObj} is a {@code Byte} object and
822 * {@code bObj.byteValue() == b}.
823 *
824 * @param obj the object whose field should be modified
825 * @param b the new value for the field of {@code obj}
826 * being modified
827 *
828 * @exception IllegalAccessException if this {@code Field} object
829 * is enforcing Java language access control and the underlying
830 * field is either inaccessible or final.
831 * @exception IllegalArgumentException if the specified object is not an
832 * instance of the class or interface declaring the underlying
833 * field (or a subclass or implementor thereof),
834 * or if an unwrapping conversion fails.
835 * @exception NullPointerException if the specified object is null
836 * and the field is an instance field.
837 * @exception ExceptionInInitializerError if the initialization provoked
838 * by this method fails.
839 * @see Field#set
840 */
841 @CallerSensitive
842 @ForceInline // to ensure Reflection.getCallerClass optimization
843 public void setByte(Object obj, byte b)
844 throws IllegalArgumentException, IllegalAccessException
845 {
846 if (!override) {
847 Class<?> caller = Reflection.getCallerClass();
848 checkAccess(caller, obj);
849 }
850 getFieldAccessor(obj).setByte(obj, b);
851 }
852
853 /**
854 * Sets the value of a field as a {@code char} on the specified object.
855 * This method is equivalent to
856 * {@code set(obj, cObj)},
857 * where {@code cObj} is a {@code Character} object and
858 * {@code cObj.charValue() == c}.
859 *
860 * @param obj the object whose field should be modified
861 * @param c the new value for the field of {@code obj}
862 * being modified
863 *
864 * @exception IllegalAccessException if this {@code Field} object
865 * is enforcing Java language access control and the underlying
866 * field is either inaccessible or final.
867 * @exception IllegalArgumentException if the specified object is not an
868 * instance of the class or interface declaring the underlying
869 * field (or a subclass or implementor thereof),
870 * or if an unwrapping conversion fails.
871 * @exception NullPointerException if the specified object is null
872 * and the field is an instance field.
873 * @exception ExceptionInInitializerError if the initialization provoked
874 * by this method fails.
875 * @see Field#set
876 */
877 @CallerSensitive
878 @ForceInline // to ensure Reflection.getCallerClass optimization
879 public void setChar(Object obj, char c)
880 throws IllegalArgumentException, IllegalAccessException
881 {
882 if (!override) {
883 Class<?> caller = Reflection.getCallerClass();
884 checkAccess(caller, obj);
885 }
886 getFieldAccessor(obj).setChar(obj, c);
887 }
888
889 /**
890 * Sets the value of a field as a {@code short} on the specified object.
891 * This method is equivalent to
892 * {@code set(obj, sObj)},
893 * where {@code sObj} is a {@code Short} object and
894 * {@code sObj.shortValue() == s}.
895 *
896 * @param obj the object whose field should be modified
897 * @param s the new value for the field of {@code obj}
898 * being modified
899 *
900 * @exception IllegalAccessException if this {@code Field} object
901 * is enforcing Java language access control and the underlying
902 * field is either inaccessible or final.
903 * @exception IllegalArgumentException if the specified object is not an
904 * instance of the class or interface declaring the underlying
905 * field (or a subclass or implementor thereof),
906 * or if an unwrapping conversion fails.
907 * @exception NullPointerException if the specified object is null
908 * and the field is an instance field.
909 * @exception ExceptionInInitializerError if the initialization provoked
910 * by this method fails.
911 * @see Field#set
912 */
913 @CallerSensitive
914 @ForceInline // to ensure Reflection.getCallerClass optimization
915 public void setShort(Object obj, short s)
916 throws IllegalArgumentException, IllegalAccessException
917 {
918 if (!override) {
919 Class<?> caller = Reflection.getCallerClass();
920 checkAccess(caller, obj);
921 }
922 getFieldAccessor(obj).setShort(obj, s);
923 }
924
925 /**
926 * Sets the value of a field as an {@code int} on the specified object.
927 * This method is equivalent to
928 * {@code set(obj, iObj)},
929 * where {@code iObj} is an {@code Integer} object and
930 * {@code iObj.intValue() == i}.
931 *
932 * @param obj the object whose field should be modified
933 * @param i the new value for the field of {@code obj}
934 * being modified
935 *
936 * @exception IllegalAccessException if this {@code Field} object
937 * is enforcing Java language access control and the underlying
938 * field is either inaccessible or final.
939 * @exception IllegalArgumentException if the specified object is not an
940 * instance of the class or interface declaring the underlying
941 * field (or a subclass or implementor thereof),
942 * or if an unwrapping conversion fails.
943 * @exception NullPointerException if the specified object is null
944 * and the field is an instance field.
945 * @exception ExceptionInInitializerError if the initialization provoked
946 * by this method fails.
947 * @see Field#set
948 */
949 @CallerSensitive
950 @ForceInline // to ensure Reflection.getCallerClass optimization
951 public void setInt(Object obj, int i)
952 throws IllegalArgumentException, IllegalAccessException
953 {
954 if (!override) {
955 Class<?> caller = Reflection.getCallerClass();
956 checkAccess(caller, obj);
957 }
958 getFieldAccessor(obj).setInt(obj, i);
959 }
960
961 /**
962 * Sets the value of a field as a {@code long} on the specified object.
963 * This method is equivalent to
964 * {@code set(obj, lObj)},
965 * where {@code lObj} is a {@code Long} object and
966 * {@code lObj.longValue() == l}.
967 *
968 * @param obj the object whose field should be modified
969 * @param l the new value for the field of {@code obj}
970 * being modified
971 *
972 * @exception IllegalAccessException if this {@code Field} object
973 * is enforcing Java language access control and the underlying
974 * field is either inaccessible or final.
975 * @exception IllegalArgumentException if the specified object is not an
976 * instance of the class or interface declaring the underlying
977 * field (or a subclass or implementor thereof),
978 * or if an unwrapping conversion fails.
979 * @exception NullPointerException if the specified object is null
980 * and the field is an instance field.
981 * @exception ExceptionInInitializerError if the initialization provoked
982 * by this method fails.
983 * @see Field#set
984 */
985 @CallerSensitive
986 @ForceInline // to ensure Reflection.getCallerClass optimization
987 public void setLong(Object obj, long l)
988 throws IllegalArgumentException, IllegalAccessException
989 {
990 if (!override) {
991 Class<?> caller = Reflection.getCallerClass();
992 checkAccess(caller, obj);
993 }
994 getFieldAccessor(obj).setLong(obj, l);
995 }
996
997 /**
998 * Sets the value of a field as a {@code float} on the specified object.
999 * This method is equivalent to
1000 * {@code set(obj, fObj)},
1001 * where {@code fObj} is a {@code Float} object and
1002 * {@code fObj.floatValue() == f}.
1003 *
1004 * @param obj the object whose field should be modified
1005 * @param f the new value for the field of {@code obj}
1006 * being modified
1007 *
1008 * @exception IllegalAccessException if this {@code Field} object
1009 * is enforcing Java language access control and the underlying
1010 * field is either inaccessible or final.
1011 * @exception IllegalArgumentException if the specified object is not an
1012 * instance of the class or interface declaring the underlying
1013 * field (or a subclass or implementor thereof),
1014 * or if an unwrapping conversion fails.
1015 * @exception NullPointerException if the specified object is null
1016 * and the field is an instance field.
1017 * @exception ExceptionInInitializerError if the initialization provoked
1018 * by this method fails.
1019 * @see Field#set
1020 */
1021 @CallerSensitive
1022 @ForceInline // to ensure Reflection.getCallerClass optimization
1023 public void setFloat(Object obj, float f)
1024 throws IllegalArgumentException, IllegalAccessException
1025 {
1026 if (!override) {
1027 Class<?> caller = Reflection.getCallerClass();
1028 checkAccess(caller, obj);
1029 }
1030 getFieldAccessor(obj).setFloat(obj, f);
1031 }
1032
1033 /**
1034 * Sets the value of a field as a {@code double} on the specified object.
1035 * This method is equivalent to
1036 * {@code set(obj, dObj)},
1037 * where {@code dObj} is a {@code Double} object and
1038 * {@code dObj.doubleValue() == d}.
1039 *
1040 * @param obj the object whose field should be modified
1041 * @param d the new value for the field of {@code obj}
1042 * being modified
1043 *
1044 * @exception IllegalAccessException if this {@code Field} object
1045 * is enforcing Java language access control and the underlying
1046 * field is either inaccessible or final.
1047 * @exception IllegalArgumentException if the specified object is not an
1048 * instance of the class or interface declaring the underlying
1049 * field (or a subclass or implementor thereof),
1050 * or if an unwrapping conversion fails.
1051 * @exception NullPointerException if the specified object is null
1052 * and the field is an instance field.
1053 * @exception ExceptionInInitializerError if the initialization provoked
1054 * by this method fails.
1055 * @see Field#set
1056 */
1057 @CallerSensitive
1058 @ForceInline // to ensure Reflection.getCallerClass optimization
1059 public void setDouble(Object obj, double d)
1060 throws IllegalArgumentException, IllegalAccessException
1061 {
1062 if (!override) {
1063 Class<?> caller = Reflection.getCallerClass();
1064 checkAccess(caller, obj);
1065 }
1066 getFieldAccessor(obj).setDouble(obj, d);
1067 }
1068
1069 // check access to field
1070 private void checkAccess(Class<?> caller, Object obj)
1071 throws IllegalAccessException
1072 {
1073 checkAccess(caller, clazz,
|
376 * <p>If this {@code Field} object is enforcing Java language access control, and
377 * the underlying field is inaccessible, the method throws an
378 * {@code IllegalAccessException}.
379 * If the underlying field is static, the class that declared the
380 * field is initialized if it has not already been initialized.
381 *
382 * <p>Otherwise, the value is retrieved from the underlying instance
383 * or static field. If the field has a primitive type, the value
384 * is wrapped in an object before being returned, otherwise it is
385 * returned as is.
386 *
387 * <p>If the field is hidden in the type of {@code obj},
388 * the field's value is obtained according to the preceding rules.
389 *
390 * @param obj object from which the represented field's value is
391 * to be extracted
392 * @return the value of the represented field in object
393 * {@code obj}; primitive values are wrapped in an appropriate
394 * object before being returned
395 *
396 * @throws IllegalAccessException if this {@code Field} object
397 * is enforcing Java language access control and the underlying
398 * field is inaccessible.
399 * @throws IllegalArgumentException if the specified object is not an
400 * instance of the class or interface declaring the underlying
401 * field (or a subclass or implementor thereof).
402 * @throws NullPointerException if the specified object is null
403 * and the field is an instance field.
404 * @throws ExceptionInInitializerError if the initialization provoked
405 * by this method fails.
406 */
407 @CallerSensitive
408 @ForceInline // to ensure Reflection.getCallerClass optimization
409 public Object get(Object obj)
410 throws IllegalArgumentException, IllegalAccessException
411 {
412 if (!override) {
413 Class<?> caller = Reflection.getCallerClass();
414 checkAccess(caller, obj);
415 }
416 return getFieldAccessor(obj).get(obj);
417 }
418
419 /**
420 * Gets the value of a static or instance {@code boolean} field.
421 *
422 * @param obj the object to extract the {@code boolean} value
423 * from
424 * @return the value of the {@code boolean} field
425 *
426 * @throws IllegalAccessException if this {@code Field} object
427 * is enforcing Java language access control and the underlying
428 * field is inaccessible.
429 * @throws IllegalArgumentException if the specified object is not
430 * an instance of the class or interface declaring the
431 * underlying field (or a subclass or implementor
432 * thereof), or if the field value cannot be
433 * converted to the type {@code boolean} by a
434 * widening conversion.
435 * @throws NullPointerException if the specified object is null
436 * and the field is an instance field.
437 * @throws ExceptionInInitializerError if the initialization provoked
438 * by this method fails.
439 * @see Field#get
440 */
441 @CallerSensitive
442 @ForceInline // to ensure Reflection.getCallerClass optimization
443 public boolean getBoolean(Object obj)
444 throws IllegalArgumentException, IllegalAccessException
445 {
446 if (!override) {
447 Class<?> caller = Reflection.getCallerClass();
448 checkAccess(caller, obj);
449 }
450 return getFieldAccessor(obj).getBoolean(obj);
451 }
452
453 /**
454 * Gets the value of a static or instance {@code byte} field.
455 *
456 * @param obj the object to extract the {@code byte} value
457 * from
458 * @return the value of the {@code byte} field
459 *
460 * @throws IllegalAccessException if this {@code Field} object
461 * is enforcing Java language access control and the underlying
462 * field is inaccessible.
463 * @throws IllegalArgumentException if the specified object is not
464 * an instance of the class or interface declaring the
465 * underlying field (or a subclass or implementor
466 * thereof), or if the field value cannot be
467 * converted to the type {@code byte} by a
468 * widening conversion.
469 * @throws NullPointerException if the specified object is null
470 * and the field is an instance field.
471 * @throws ExceptionInInitializerError if the initialization provoked
472 * by this method fails.
473 * @see Field#get
474 */
475 @CallerSensitive
476 @ForceInline // to ensure Reflection.getCallerClass optimization
477 public byte getByte(Object obj)
478 throws IllegalArgumentException, IllegalAccessException
479 {
480 if (!override) {
481 Class<?> caller = Reflection.getCallerClass();
482 checkAccess(caller, obj);
483 }
484 return getFieldAccessor(obj).getByte(obj);
485 }
486
487 /**
488 * Gets the value of a static or instance field of type
489 * {@code char} or of another primitive type convertible to
490 * type {@code char} via a widening conversion.
491 *
492 * @param obj the object to extract the {@code char} value
493 * from
494 * @return the value of the field converted to type {@code char}
495 *
496 * @throws IllegalAccessException if this {@code Field} object
497 * is enforcing Java language access control and the underlying
498 * field is inaccessible.
499 * @throws IllegalArgumentException if the specified object is not
500 * an instance of the class or interface declaring the
501 * underlying field (or a subclass or implementor
502 * thereof), or if the field value cannot be
503 * converted to the type {@code char} by a
504 * widening conversion.
505 * @throws NullPointerException if the specified object is null
506 * and the field is an instance field.
507 * @throws ExceptionInInitializerError if the initialization provoked
508 * by this method fails.
509 * @see Field#get
510 */
511 @CallerSensitive
512 @ForceInline // to ensure Reflection.getCallerClass optimization
513 public char getChar(Object obj)
514 throws IllegalArgumentException, IllegalAccessException
515 {
516 if (!override) {
517 Class<?> caller = Reflection.getCallerClass();
518 checkAccess(caller, obj);
519 }
520 return getFieldAccessor(obj).getChar(obj);
521 }
522
523 /**
524 * Gets the value of a static or instance field of type
525 * {@code short} or of another primitive type convertible to
526 * type {@code short} via a widening conversion.
527 *
528 * @param obj the object to extract the {@code short} value
529 * from
530 * @return the value of the field converted to type {@code short}
531 *
532 * @throws IllegalAccessException if this {@code Field} object
533 * is enforcing Java language access control and the underlying
534 * field is inaccessible.
535 * @throws IllegalArgumentException if the specified object is not
536 * an instance of the class or interface declaring the
537 * underlying field (or a subclass or implementor
538 * thereof), or if the field value cannot be
539 * converted to the type {@code short} by a
540 * widening conversion.
541 * @throws NullPointerException if the specified object is null
542 * and the field is an instance field.
543 * @throws ExceptionInInitializerError if the initialization provoked
544 * by this method fails.
545 * @see Field#get
546 */
547 @CallerSensitive
548 @ForceInline // to ensure Reflection.getCallerClass optimization
549 public short getShort(Object obj)
550 throws IllegalArgumentException, IllegalAccessException
551 {
552 if (!override) {
553 Class<?> caller = Reflection.getCallerClass();
554 checkAccess(caller, obj);
555 }
556 return getFieldAccessor(obj).getShort(obj);
557 }
558
559 /**
560 * Gets the value of a static or instance field of type
561 * {@code int} or of another primitive type convertible to
562 * type {@code int} via a widening conversion.
563 *
564 * @param obj the object to extract the {@code int} value
565 * from
566 * @return the value of the field converted to type {@code int}
567 *
568 * @throws IllegalAccessException if this {@code Field} object
569 * is enforcing Java language access control and the underlying
570 * field is inaccessible.
571 * @throws IllegalArgumentException if the specified object is not
572 * an instance of the class or interface declaring the
573 * underlying field (or a subclass or implementor
574 * thereof), or if the field value cannot be
575 * converted to the type {@code int} by a
576 * widening conversion.
577 * @throws NullPointerException if the specified object is null
578 * and the field is an instance field.
579 * @throws ExceptionInInitializerError if the initialization provoked
580 * by this method fails.
581 * @see Field#get
582 */
583 @CallerSensitive
584 @ForceInline // to ensure Reflection.getCallerClass optimization
585 public int getInt(Object obj)
586 throws IllegalArgumentException, IllegalAccessException
587 {
588 if (!override) {
589 Class<?> caller = Reflection.getCallerClass();
590 checkAccess(caller, obj);
591 }
592 return getFieldAccessor(obj).getInt(obj);
593 }
594
595 /**
596 * Gets the value of a static or instance field of type
597 * {@code long} or of another primitive type convertible to
598 * type {@code long} via a widening conversion.
599 *
600 * @param obj the object to extract the {@code long} value
601 * from
602 * @return the value of the field converted to type {@code long}
603 *
604 * @throws IllegalAccessException if this {@code Field} object
605 * is enforcing Java language access control and the underlying
606 * field is inaccessible.
607 * @throws IllegalArgumentException if the specified object is not
608 * an instance of the class or interface declaring the
609 * underlying field (or a subclass or implementor
610 * thereof), or if the field value cannot be
611 * converted to the type {@code long} by a
612 * widening conversion.
613 * @throws NullPointerException if the specified object is null
614 * and the field is an instance field.
615 * @throws ExceptionInInitializerError if the initialization provoked
616 * by this method fails.
617 * @see Field#get
618 */
619 @CallerSensitive
620 @ForceInline // to ensure Reflection.getCallerClass optimization
621 public long getLong(Object obj)
622 throws IllegalArgumentException, IllegalAccessException
623 {
624 if (!override) {
625 Class<?> caller = Reflection.getCallerClass();
626 checkAccess(caller, obj);
627 }
628 return getFieldAccessor(obj).getLong(obj);
629 }
630
631 /**
632 * Gets the value of a static or instance field of type
633 * {@code float} or of another primitive type convertible to
634 * type {@code float} via a widening conversion.
635 *
636 * @param obj the object to extract the {@code float} value
637 * from
638 * @return the value of the field converted to type {@code float}
639 *
640 * @throws IllegalAccessException if this {@code Field} object
641 * is enforcing Java language access control and the underlying
642 * field is inaccessible.
643 * @throws IllegalArgumentException if the specified object is not
644 * an instance of the class or interface declaring the
645 * underlying field (or a subclass or implementor
646 * thereof), or if the field value cannot be
647 * converted to the type {@code float} by a
648 * widening conversion.
649 * @throws NullPointerException if the specified object is null
650 * and the field is an instance field.
651 * @throws ExceptionInInitializerError if the initialization provoked
652 * by this method fails.
653 * @see Field#get
654 */
655 @CallerSensitive
656 @ForceInline // to ensure Reflection.getCallerClass optimization
657 public float getFloat(Object obj)
658 throws IllegalArgumentException, IllegalAccessException
659 {
660 if (!override) {
661 Class<?> caller = Reflection.getCallerClass();
662 checkAccess(caller, obj);
663 }
664 return getFieldAccessor(obj).getFloat(obj);
665 }
666
667 /**
668 * Gets the value of a static or instance field of type
669 * {@code double} or of another primitive type convertible to
670 * type {@code double} via a widening conversion.
671 *
672 * @param obj the object to extract the {@code double} value
673 * from
674 * @return the value of the field converted to type {@code double}
675 *
676 * @throws IllegalAccessException if this {@code Field} object
677 * is enforcing Java language access control and the underlying
678 * field is inaccessible.
679 * @throws IllegalArgumentException if the specified object is not
680 * an instance of the class or interface declaring the
681 * underlying field (or a subclass or implementor
682 * thereof), or if the field value cannot be
683 * converted to the type {@code double} by a
684 * widening conversion.
685 * @throws NullPointerException if the specified object is null
686 * and the field is an instance field.
687 * @throws ExceptionInInitializerError if the initialization provoked
688 * by this method fails.
689 * @see Field#get
690 */
691 @CallerSensitive
692 @ForceInline // to ensure Reflection.getCallerClass optimization
693 public double getDouble(Object obj)
694 throws IllegalArgumentException, IllegalAccessException
695 {
696 if (!override) {
697 Class<?> caller = Reflection.getCallerClass();
698 checkAccess(caller, obj);
699 }
700 return getFieldAccessor(obj).getDouble(obj);
701 }
702
703 /**
704 * Sets the field represented by this {@code Field} object on the
705 * specified object argument to the specified new value. The new
706 * value is automatically unwrapped if the underlying field has a
707 * primitive type.
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 *
748 * <p>The field is set to the possibly unwrapped and widened new value.
749 *
750 * <p>If the field is hidden in the type of {@code obj},
751 * the field's value is set according to the preceding rules.
752 *
753 * @param obj the object whose field should be modified
754 * @param value the new value for the field of {@code obj}
755 * being modified
756 *
757 * @throws IllegalAccessException if this {@code Field} object
758 * is enforcing Java language access control and the underlying
759 * field is either inaccessible or final.
760 * @throws IllegalArgumentException if the specified object is not an
761 * instance of the class or interface declaring the underlying
762 * field (or a subclass or implementor thereof),
763 * or if an unwrapping conversion fails.
764 * @throws NullPointerException if the specified object is null
765 * and the field is an instance field.
766 * @throws ExceptionInInitializerError if the initialization provoked
767 * by this method fails.
768 */
769 @CallerSensitive
770 @ForceInline // to ensure Reflection.getCallerClass optimization
771 public void set(Object obj, Object value)
772 throws IllegalArgumentException, IllegalAccessException
773 {
774 if (!override) {
775 Class<?> caller = Reflection.getCallerClass();
776 checkAccess(caller, obj);
777 }
778 getFieldAccessor(obj).set(obj, value);
779 }
780
781 /**
782 * Sets the value of a field as a {@code boolean} on the specified object.
783 * This method is equivalent to
784 * {@code set(obj, zObj)},
785 * where {@code zObj} is a {@code Boolean} object and
786 * {@code zObj.booleanValue() == z}.
787 *
788 * @param obj the object whose field should be modified
789 * @param z the new value for the field of {@code obj}
790 * being modified
791 *
792 * @throws IllegalAccessException if this {@code Field} object
793 * is enforcing Java language access control and the underlying
794 * field is either inaccessible or final.
795 * @throws IllegalArgumentException if the specified object is not an
796 * instance of the class or interface declaring the underlying
797 * field (or a subclass or implementor thereof),
798 * or if an unwrapping conversion fails.
799 * @throws NullPointerException if the specified object is null
800 * and the field is an instance field.
801 * @throws ExceptionInInitializerError if the initialization provoked
802 * by this method fails.
803 * @see Field#set
804 */
805 @CallerSensitive
806 @ForceInline // to ensure Reflection.getCallerClass optimization
807 public void setBoolean(Object obj, boolean z)
808 throws IllegalArgumentException, IllegalAccessException
809 {
810 if (!override) {
811 Class<?> caller = Reflection.getCallerClass();
812 checkAccess(caller, obj);
813 }
814 getFieldAccessor(obj).setBoolean(obj, z);
815 }
816
817 /**
818 * Sets the value of a field as a {@code byte} on the specified object.
819 * This method is equivalent to
820 * {@code set(obj, bObj)},
821 * where {@code bObj} is a {@code Byte} object and
822 * {@code bObj.byteValue() == b}.
823 *
824 * @param obj the object whose field should be modified
825 * @param b the new value for the field of {@code obj}
826 * being modified
827 *
828 * @throws IllegalAccessException if this {@code Field} object
829 * is enforcing Java language access control and the underlying
830 * field is either inaccessible or final.
831 * @throws IllegalArgumentException if the specified object is not an
832 * instance of the class or interface declaring the underlying
833 * field (or a subclass or implementor thereof),
834 * or if an unwrapping conversion fails.
835 * @throws NullPointerException if the specified object is null
836 * and the field is an instance field.
837 * @throws ExceptionInInitializerError if the initialization provoked
838 * by this method fails.
839 * @see Field#set
840 */
841 @CallerSensitive
842 @ForceInline // to ensure Reflection.getCallerClass optimization
843 public void setByte(Object obj, byte b)
844 throws IllegalArgumentException, IllegalAccessException
845 {
846 if (!override) {
847 Class<?> caller = Reflection.getCallerClass();
848 checkAccess(caller, obj);
849 }
850 getFieldAccessor(obj).setByte(obj, b);
851 }
852
853 /**
854 * Sets the value of a field as a {@code char} on the specified object.
855 * This method is equivalent to
856 * {@code set(obj, cObj)},
857 * where {@code cObj} is a {@code Character} object and
858 * {@code cObj.charValue() == c}.
859 *
860 * @param obj the object whose field should be modified
861 * @param c the new value for the field of {@code obj}
862 * being modified
863 *
864 * @throws IllegalAccessException if this {@code Field} object
865 * is enforcing Java language access control and the underlying
866 * field is either inaccessible or final.
867 * @throws IllegalArgumentException if the specified object is not an
868 * instance of the class or interface declaring the underlying
869 * field (or a subclass or implementor thereof),
870 * or if an unwrapping conversion fails.
871 * @throws NullPointerException if the specified object is null
872 * and the field is an instance field.
873 * @throws ExceptionInInitializerError if the initialization provoked
874 * by this method fails.
875 * @see Field#set
876 */
877 @CallerSensitive
878 @ForceInline // to ensure Reflection.getCallerClass optimization
879 public void setChar(Object obj, char c)
880 throws IllegalArgumentException, IllegalAccessException
881 {
882 if (!override) {
883 Class<?> caller = Reflection.getCallerClass();
884 checkAccess(caller, obj);
885 }
886 getFieldAccessor(obj).setChar(obj, c);
887 }
888
889 /**
890 * Sets the value of a field as a {@code short} on the specified object.
891 * This method is equivalent to
892 * {@code set(obj, sObj)},
893 * where {@code sObj} is a {@code Short} object and
894 * {@code sObj.shortValue() == s}.
895 *
896 * @param obj the object whose field should be modified
897 * @param s the new value for the field of {@code obj}
898 * being modified
899 *
900 * @throws IllegalAccessException if this {@code Field} object
901 * is enforcing Java language access control and the underlying
902 * field is either inaccessible or final.
903 * @throws IllegalArgumentException if the specified object is not an
904 * instance of the class or interface declaring the underlying
905 * field (or a subclass or implementor thereof),
906 * or if an unwrapping conversion fails.
907 * @throws NullPointerException if the specified object is null
908 * and the field is an instance field.
909 * @throws ExceptionInInitializerError if the initialization provoked
910 * by this method fails.
911 * @see Field#set
912 */
913 @CallerSensitive
914 @ForceInline // to ensure Reflection.getCallerClass optimization
915 public void setShort(Object obj, short s)
916 throws IllegalArgumentException, IllegalAccessException
917 {
918 if (!override) {
919 Class<?> caller = Reflection.getCallerClass();
920 checkAccess(caller, obj);
921 }
922 getFieldAccessor(obj).setShort(obj, s);
923 }
924
925 /**
926 * Sets the value of a field as an {@code int} on the specified object.
927 * This method is equivalent to
928 * {@code set(obj, iObj)},
929 * where {@code iObj} is an {@code Integer} object and
930 * {@code iObj.intValue() == i}.
931 *
932 * @param obj the object whose field should be modified
933 * @param i the new value for the field of {@code obj}
934 * being modified
935 *
936 * @throws IllegalAccessException if this {@code Field} object
937 * is enforcing Java language access control and the underlying
938 * field is either inaccessible or final.
939 * @throws IllegalArgumentException if the specified object is not an
940 * instance of the class or interface declaring the underlying
941 * field (or a subclass or implementor thereof),
942 * or if an unwrapping conversion fails.
943 * @throws NullPointerException if the specified object is null
944 * and the field is an instance field.
945 * @throws ExceptionInInitializerError if the initialization provoked
946 * by this method fails.
947 * @see Field#set
948 */
949 @CallerSensitive
950 @ForceInline // to ensure Reflection.getCallerClass optimization
951 public void setInt(Object obj, int i)
952 throws IllegalArgumentException, IllegalAccessException
953 {
954 if (!override) {
955 Class<?> caller = Reflection.getCallerClass();
956 checkAccess(caller, obj);
957 }
958 getFieldAccessor(obj).setInt(obj, i);
959 }
960
961 /**
962 * Sets the value of a field as a {@code long} on the specified object.
963 * This method is equivalent to
964 * {@code set(obj, lObj)},
965 * where {@code lObj} is a {@code Long} object and
966 * {@code lObj.longValue() == l}.
967 *
968 * @param obj the object whose field should be modified
969 * @param l the new value for the field of {@code obj}
970 * being modified
971 *
972 * @throws IllegalAccessException if this {@code Field} object
973 * is enforcing Java language access control and the underlying
974 * field is either inaccessible or final.
975 * @throws IllegalArgumentException if the specified object is not an
976 * instance of the class or interface declaring the underlying
977 * field (or a subclass or implementor thereof),
978 * or if an unwrapping conversion fails.
979 * @throws NullPointerException if the specified object is null
980 * and the field is an instance field.
981 * @throws ExceptionInInitializerError if the initialization provoked
982 * by this method fails.
983 * @see Field#set
984 */
985 @CallerSensitive
986 @ForceInline // to ensure Reflection.getCallerClass optimization
987 public void setLong(Object obj, long l)
988 throws IllegalArgumentException, IllegalAccessException
989 {
990 if (!override) {
991 Class<?> caller = Reflection.getCallerClass();
992 checkAccess(caller, obj);
993 }
994 getFieldAccessor(obj).setLong(obj, l);
995 }
996
997 /**
998 * Sets the value of a field as a {@code float} on the specified object.
999 * This method is equivalent to
1000 * {@code set(obj, fObj)},
1001 * where {@code fObj} is a {@code Float} object and
1002 * {@code fObj.floatValue() == f}.
1003 *
1004 * @param obj the object whose field should be modified
1005 * @param f the new value for the field of {@code obj}
1006 * being modified
1007 *
1008 * @throws IllegalAccessException if this {@code Field} object
1009 * is enforcing Java language access control and the underlying
1010 * field is either inaccessible or final.
1011 * @throws IllegalArgumentException if the specified object is not an
1012 * instance of the class or interface declaring the underlying
1013 * field (or a subclass or implementor thereof),
1014 * or if an unwrapping conversion fails.
1015 * @throws NullPointerException if the specified object is null
1016 * and the field is an instance field.
1017 * @throws ExceptionInInitializerError if the initialization provoked
1018 * by this method fails.
1019 * @see Field#set
1020 */
1021 @CallerSensitive
1022 @ForceInline // to ensure Reflection.getCallerClass optimization
1023 public void setFloat(Object obj, float f)
1024 throws IllegalArgumentException, IllegalAccessException
1025 {
1026 if (!override) {
1027 Class<?> caller = Reflection.getCallerClass();
1028 checkAccess(caller, obj);
1029 }
1030 getFieldAccessor(obj).setFloat(obj, f);
1031 }
1032
1033 /**
1034 * Sets the value of a field as a {@code double} on the specified object.
1035 * This method is equivalent to
1036 * {@code set(obj, dObj)},
1037 * where {@code dObj} is a {@code Double} object and
1038 * {@code dObj.doubleValue() == d}.
1039 *
1040 * @param obj the object whose field should be modified
1041 * @param d the new value for the field of {@code obj}
1042 * being modified
1043 *
1044 * @throws IllegalAccessException if this {@code Field} object
1045 * is enforcing Java language access control and the underlying
1046 * field is either inaccessible or final.
1047 * @throws IllegalArgumentException if the specified object is not an
1048 * instance of the class or interface declaring the underlying
1049 * field (or a subclass or implementor thereof),
1050 * or if an unwrapping conversion fails.
1051 * @throws NullPointerException if the specified object is null
1052 * and the field is an instance field.
1053 * @throws ExceptionInInitializerError if the initialization provoked
1054 * by this method fails.
1055 * @see Field#set
1056 */
1057 @CallerSensitive
1058 @ForceInline // to ensure Reflection.getCallerClass optimization
1059 public void setDouble(Object obj, double d)
1060 throws IllegalArgumentException, IllegalAccessException
1061 {
1062 if (!override) {
1063 Class<?> caller = Reflection.getCallerClass();
1064 checkAccess(caller, obj);
1065 }
1066 getFieldAccessor(obj).setDouble(obj, d);
1067 }
1068
1069 // check access to field
1070 private void checkAccess(Class<?> caller, Object obj)
1071 throws IllegalAccessException
1072 {
1073 checkAccess(caller, clazz,
|