< prev index next >

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

Print this page




 150         if (this.root != null)
 151             throw new IllegalArgumentException("Can not copy a non-root Field");
 152 
 153         Field res = new Field(clazz, name, type, modifiers, slot, signature, annotations);
 154         res.root = this;
 155         // Might as well eagerly propagate this if already present
 156         res.fieldAccessor = fieldAccessor;
 157         res.overrideFieldAccessor = overrideFieldAccessor;
 158 
 159         return res;
 160     }
 161 
 162     /**
 163      * @throws InaccessibleObjectException {@inheritDoc}
 164      * @throws SecurityException {@inheritDoc}
 165      */
 166     @Override
 167     @CallerSensitive
 168     public void setAccessible(boolean flag) {
 169         AccessibleObject.checkPermission();






 170         if (flag) checkCanSetAccessible(Reflection.getCallerClass());
 171         setAccessible0(flag);
 172     }
 173 
 174     @Override
 175     void checkCanSetAccessible(Class<?> caller) {
 176         checkCanSetAccessible(caller, clazz);
 177     }
 178 
 179     /**
 180      * Returns the {@code Class} object representing the class or interface
 181      * that declares the field represented by this {@code Field} object.
 182      */
 183     @Override
 184     public Class<?> getDeclaringClass() {
 185         return clazz;
 186     }
 187 
 188     /**
 189      * Returns the name of the field represented by this {@code Field} object.




 150         if (this.root != null)
 151             throw new IllegalArgumentException("Can not copy a non-root Field");
 152 
 153         Field res = new Field(clazz, name, type, modifiers, slot, signature, annotations);
 154         res.root = this;
 155         // Might as well eagerly propagate this if already present
 156         res.fieldAccessor = fieldAccessor;
 157         res.overrideFieldAccessor = overrideFieldAccessor;
 158 
 159         return res;
 160     }
 161 
 162     /**
 163      * @throws InaccessibleObjectException {@inheritDoc}
 164      * @throws SecurityException {@inheritDoc}
 165      */
 166     @Override
 167     @CallerSensitive
 168     public void setAccessible(boolean flag) {
 169         AccessibleObject.checkPermission();
 170 
 171         if (clazz.isValue() && Modifier.isFinal(modifiers)) {
 172             throw new InaccessibleObjectException(
 173                 "Unable to make a value class field \"" + this + "\" accessible");
 174         }
 175 
 176         if (flag) checkCanSetAccessible(Reflection.getCallerClass());
 177         setAccessible0(flag);
 178     }
 179 
 180     @Override
 181     void checkCanSetAccessible(Class<?> caller) {
 182         checkCanSetAccessible(caller, clazz);
 183     }
 184 
 185     /**
 186      * Returns the {@code Class} object representing the class or interface
 187      * that declares the field represented by this {@code Field} object.
 188      */
 189     @Override
 190     public Class<?> getDeclaringClass() {
 191         return clazz;
 192     }
 193 
 194     /**
 195      * Returns the name of the field represented by this {@code Field} object.


< prev index next >