Package: org.codehaus.groovy.reflection.stdclasses

## [Java] Class CachedSAMClass

- org.codehaus.groovy.reflection.stdclasses.CachedSAMClass

-     public class CachedSAMClass
      extends CachedClass

  Provides optimized reflection caching for Single Abstract Method (SAM) types. Converts Closure arguments to SAM interface implementations via dynamic proxies or aggregates.

- - Inherited fields
    Fields inherited from class | Fields
    --- | ---
    `class CachedClass` | `EMPTY_ARRAY, classInfo, isArray, isInterface, isNumber, isPrimitive, modifiers, mopMethods`

  - ### Constructor Summary

    Constructors
    Constructor and description
    `CachedSAMClass(Class clazz, ClassInfo classInfo)` Constructs a cached class representation for a SAM type.

  - ### Methods Summary

    Methods
    Type Params | Return Type | Name and description
    --- | --- | ---
    `` | `public Object` | `coerceArgument(Object argument)` Coerces the given argument to this SAM type.
    `` | `public static Object` | `coerceToSAM(Closure argument, Method method, Class clazz)` Coerces a closure to a SAM interface implementation.
    `` | `public static Object` | `coerceToSAM(Closure argument, Method method, Class clazz, boolean isInterface)` Coerces a closure to a SAM interface or class implementation.
    `` | `public static Method` | `getSAMMethod(Class<?> c)` Finds the abstract method of given class, if it is a SAM type.
    `` | `public boolean` | `isAssignableFrom(Class argument)` Determines if the given class is assignable to this SAM type.

  - ### Inherited Methods Summary

    Inherited Methods
    Methods inherited from class | Name
    --- | ---
    `class CachedClass` | `addNewMopMethods, coerceArgument, getCachedClass, getCachedSuperClass, getConstructors, getDeclaredInterfaces, getFields, getHierarchy, getInterfaces, getMethods, getModifiers, getName, getNewMetaMethods, getSuperClassDistance, getTheClass, getTypeDescription, hashCode, isAssignableFrom, isDirectlyAssignable, isInterface, isPrimitive, isVoid, searchMethods, setNewMopMethods, toString`

- - ### Constructor Detail

    - #### public CachedSAMClass(Class clazz, ClassInfo classInfo)

      Constructs a cached class representation for a SAM type. Locates and caches the single abstract method of the class.

      throws:
        GroovyBugError if the class does not have exactly one abstract method
      Parameters:
        `clazz` - the SAM type to cache
        `classInfo` - the class information associated with this cached class

  - ### Method Detail

    - #### public Object coerceArgument(Object argument)

      Coerces the given argument to this SAM type. Converts Closure arguments to SAM interface implementations via dynamic proxies.

      Parameters:
        `argument` - the argument to coerce
      Returns:
        the coerced SAM instance, or the original argument if already compatible

    - #### public static Object coerceToSAM(Closure argument, Method method, Class clazz)

      Coerces a closure to a SAM interface implementation. Automatically detects whether the SAM type is an interface or class.

      Parameters:
        `argument` - the closure to convert
        `method` - the single abstract method of the SAM type
        `clazz` - the SAM class or interface to coerce to
      Returns:
        a dynamic proxy or aggregate instance implementing the SAM type

    - #### public static Object coerceToSAM(Closure argument, Method method, Class clazz, boolean isInterface)

      Coerces a closure to a SAM interface or class implementation. For interfaces, uses dynamic proxies or trait-aware aggregates. For classes, uses proxy generators to instantiate from base class.

      Parameters:
        `argument` - the closure to convert
        `method` - the single abstract method of the SAM type
        `clazz` - the SAM class or interface to coerce to
        `isInterface` - `true` if the SAM type is an interface, `false` for a class
      Returns:
        a dynamic proxy or aggregate instance implementing the SAM type

    - #### public static Method getSAMMethod(Class<?> c)

      Finds the abstract method of given class, if it is a SAM type.

    - #### public boolean isAssignableFrom(Class argument)

      Determines if the given class is assignable to this SAM type. Accepts `null`, Closure instances, and instances already assignable to the SAM type.

      Parameters:
        `argument` - the class to check
      Returns:
        `true` if the class can be assigned to this SAM type, `false` otherwise