< prev index next >

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

Print this page




 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 (flag) {
 172             if (clazz.isValue() && Modifier.isFinal(modifiers)) {
 173                 throw new InaccessibleObjectException(
 174                     "Unable to make a value class field \"" + this + "\" accessible");
 175             }
 176 
 177             checkCanSetAccessible(Reflection.getCallerClass());
 178         }
 179         setAccessible0(flag);
 180     }
 181 
 182     @Override
 183     void checkCanSetAccessible(Class<?> caller) {
 184         checkCanSetAccessible(caller, clazz);
 185     }
 186 
 187     /**
 188      * Returns the {@code Class} object representing the class or interface
 189      * that declares the field represented by this {@code Field} object.
 190      */
 191     @Override
 192     public Class<?> getDeclaringClass() {




 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 (flag) {
 172             if (clazz.isValue()) {
 173                 throw new InaccessibleObjectException(
 174                     "Unable to make a value class field \"" + this + "\" accessible");
 175             }
 176 
 177             checkCanSetAccessible(Reflection.getCallerClass());
 178         }
 179         setAccessible0(flag);
 180     }
 181 
 182     @Override
 183     void checkCanSetAccessible(Class<?> caller) {
 184         checkCanSetAccessible(caller, clazz);
 185     }
 186 
 187     /**
 188      * Returns the {@code Class} object representing the class or interface
 189      * that declares the field represented by this {@code Field} object.
 190      */
 191     @Override
 192     public Class<?> getDeclaringClass() {


< prev index next >