< prev index next >

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

Print this page




 141     Field copy() {
 142         // This routine enables sharing of FieldAccessor objects
 143         // among Field objects which refer to the same underlying
 144         // method in the VM. (All of this contortion is only necessary
 145         // because of the "accessibility" bit in AccessibleObject,
 146         // which implicitly requires that new java.lang.reflect
 147         // objects be fabricated for each reflective call on Class
 148         // objects.)
 149         if (this.root != null)
 150             throw new IllegalArgumentException("Can not copy a non-root Field");
 151 
 152         Field res = new Field(clazz, name, type, modifiers, slot, signature, annotations);
 153         res.root = this;
 154         // Might as well eagerly propagate this if already present
 155         res.fieldAccessor = fieldAccessor;
 156         res.overrideFieldAccessor = overrideFieldAccessor;
 157 
 158         return res;
 159     }
 160 




 161     @Override
 162     @CallerSensitive
 163     public void setAccessible(boolean flag) {
 164         AccessibleObject.checkPermission();
 165         if (flag) checkCanSetAccessible(Reflection.getCallerClass());
 166         setAccessible0(flag);
 167     }
 168 
 169     @Override
 170     void checkCanSetAccessible(Class<?> caller) {
 171         checkCanSetAccessible(caller, clazz);
 172     }
 173 
 174     /**
 175      * Returns the {@code Class} object representing the class or interface
 176      * that declares the field represented by this {@code Field} object.
 177      */
 178     @Override
 179     public Class<?> getDeclaringClass() {
 180         return clazz;




 141     Field copy() {
 142         // This routine enables sharing of FieldAccessor objects
 143         // among Field objects which refer to the same underlying
 144         // method in the VM. (All of this contortion is only necessary
 145         // because of the "accessibility" bit in AccessibleObject,
 146         // which implicitly requires that new java.lang.reflect
 147         // objects be fabricated for each reflective call on Class
 148         // objects.)
 149         if (this.root != null)
 150             throw new IllegalArgumentException("Can not copy a non-root Field");
 151 
 152         Field res = new Field(clazz, name, type, modifiers, slot, signature, annotations);
 153         res.root = this;
 154         // Might as well eagerly propagate this if already present
 155         res.fieldAccessor = fieldAccessor;
 156         res.overrideFieldAccessor = overrideFieldAccessor;
 157 
 158         return res;
 159     }
 160 
 161     /**
 162      * @throws InaccessibleObjectException {@inheritDoc}
 163      * @throws SecurityException {@inheritDoc}
 164      */
 165     @Override
 166     @CallerSensitive
 167     public void setAccessible(boolean flag) {
 168         AccessibleObject.checkPermission();
 169         if (flag) checkCanSetAccessible(Reflection.getCallerClass());
 170         setAccessible0(flag);
 171     }
 172 
 173     @Override
 174     void checkCanSetAccessible(Class<?> caller) {
 175         checkCanSetAccessible(caller, clazz);
 176     }
 177 
 178     /**
 179      * Returns the {@code Class} object representing the class or interface
 180      * that declares the field represented by this {@code Field} object.
 181      */
 182     @Override
 183     public Class<?> getDeclaringClass() {
 184         return clazz;


< prev index next >