public class CachedField
extends MetaProperty
Caches reflection information about a single field for efficient access and modification.
Extends MetaProperty to integrate with the meta-programming framework. Handles lazy field accessibility and provides property-like access to field values.
| Fields inherited from class | Fields |
|---|---|
class MetaProperty |
PROPERTY_SET_PREFIX, name, type |
| Constructor and description |
|---|
CachedField(Field field)Constructs a CachedField for the given Java field. |
| Type Params | Return Type | Name and description |
|---|---|---|
|
public MethodHandle |
asAccessMethod(Lookup lookup)Creates a method handle that provides getter access to this field via MethodHandles API. |
|
public MethodHandle |
asWriteAccessMethod(Lookup lookup)Creates a method handle that writes this field via the MethodHandles API, the mutating counterpart of asAccessMethod(MethodHandles.Lookup), with the same caching policy. |
|
public boolean |
canAccessViaReflection()Determines whether the reflective access path ( Field.get/set)
can reach this field: deep access has been, or can now be, established. |
|
public Field |
getCachedField()Returns the underlying Java Field object, making it accessible if necessary. |
|
public Class |
getDeclaringClass()Returns the class that declares this field. |
|
public int |
getModifiers()* Returns the access modifiers. * *
|
|
public Object |
getProperty(Object object)*
|
|
public boolean |
isAnnotationPresent(Class<? extends Annotation> annotationType)Checks whether the underlying field has the specified annotation. |
|
public void |
setProperty(Object object, Object newValue)* Sets the property on the given object to the new value. * *
|
| Methods inherited from class | Name |
|---|---|
class MetaProperty |
getGetterName, getModifiers, getName, getProperty, getSetterName, getType, setProperty |
Constructs a CachedField for the given Java field.
field - the field to cache reflection information for Creates a method handle that provides getter access to this field via MethodHandles API.
When deep-reflection access can be established (setAccessible on the field),
the resulting handle is caller-independent and is created once and cached; otherwise
the given caller lookup decides, and its handle -- which carries that caller's access
rights -- is never cached.
lookup - the method handles lookup context of the callerCreates a method handle that writes this field via the MethodHandles API, the mutating counterpart of asAccessMethod(MethodHandles.Lookup), with the same caching policy. No deep-reflection handle is created for a final field: writing it must keep failing the caller's access check.
lookup - the method handles lookup context of the caller(declaringClass, fieldType)void Determines whether the reflective access path (Field.get/set)
can reach this field: deep access has been, or can now be, established. The
reflective path's callers use this to treat an unreachable field (strongly
encapsulated declaring class) as absent instead of failing when it is read
or written. It says nothing about what a caller's own Lookup may
reach -- see asAccessMethod(MethodHandles.Lookup) -- and so must
not be used to decide member selection or call-site linkage.
Returns the underlying Java Field object, making it accessible if necessary.
Returns the class that declares this field.
* Returns the access modifiers. * *
*
Checks whether the underlying field has the specified annotation. Unlike getCachedField(), this does not trigger accessibility changes.
Copyright © 2003-2026 The Apache Software Foundation. All rights reserved.