Package: org.codehaus.groovy.reflection

## [Java] Class CachedField

- org.codehaus.groovy.reflection.CachedField

-     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.

- - Inherited fields
    Fields inherited from class | Fields
    --- | ---
    `class MetaProperty` | `PROPERTY_SET_PREFIX, name, type`

  - ### Constructor Summary

    Constructors
    Constructor and description
    `CachedField(Field field)` Constructs a `CachedField` for the given Java field.

  - ### Methods Summary

    Methods
    Type Params | Return Type | Name and description
    --- | --- | ---
    `` | `public MethodHandle` | `asAccessMethod(MethodHandles.Lookup lookup)` Creates a method handle that provides getter access to this field via MethodHandles API.
    `` | `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. Returns: Modifier.PUBLIC
    `` | `public Object` | `getProperty(Object object)` throws: RuntimeException if the property could not be evaluated Returns: the property of the given 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. throws: RuntimeException if the property could not be set Parameters: `object` - on which to set the property `newValue` - the new value of the property

  - ### Inherited Methods Summary

    Inherited Methods
    Methods inherited from class | Name
    --- | ---
    `class MetaProperty` | `getGetterName, getModifiers, getName, getProperty, getSetterName, getType, setProperty`

- - ### Constructor Detail

    - #### public CachedField(Field field)

      Constructs a `CachedField` for the given Java field.

      Parameters:
        `field` - the field to cache reflection information for

  - ### Method Detail

    - #### public MethodHandle asAccessMethod(MethodHandles.Lookup lookup)

      Creates a method handle that provides getter access to this field via MethodHandles API. Attempts to unreflect the field, automatically making it accessible if needed.

      throws:
        IllegalAccessException if the field cannot be accessed even with accessibility adjustments
      Parameters:
        `lookup` - the method handles lookup context
      Returns:
        a method handle providing getter access to this field

    - #### public Field getCachedField()

      Returns the underlying Java `Field` object, making it accessible if necessary.

      Returns:
        the cached field with accessibility ensured

    - #### public Class getDeclaringClass()

      Returns the class that declares this field.

      Returns:
        the declaring class

    - #### public int getModifiers()

      Returns the access modifiers.

      Returns:
        Modifier.PUBLIC

    - #### public Object getProperty(Object object)

      throws:
        RuntimeException if the property could not be evaluated
      Returns:
        the property of the given object

    - #### public boolean isAnnotationPresent(Class<? extends Annotation> annotationType)

      Checks whether the underlying field has the specified annotation. Unlike getCachedField(), this does not trigger accessibility changes.

      Since:
        6.0.0

    - #### public void setProperty(Object object, Object newValue)

      Sets the property on the given object to the new value.

      throws:
        RuntimeException if the property could not be set
      Parameters:
        `object` - on which to set the property
        `newValue` - the new value of the property