Package: org.codehaus.groovy.reflection

## [Java] Class CachedConstructor

- org.codehaus.groovy.reflection.CachedConstructor

- All Implemented Interfaces and Traits:
    MetaMember

      public class CachedConstructor
      extends ParameterTypes
      implements MetaMember

  Caches reflection information about a single constructor for fast lookup and invocation.

  Extends ParameterTypes to manage parameter type information and implements MetaMember for meta-programming support. Provides methods to invoke constructors with argument coercion and error handling.

- - ### Constructor Summary

    Constructors
    Constructor and description
    `CachedConstructor(CachedClass clazz, Constructor c)` Constructs a `CachedConstructor` for the given constructor within a cached class.
    `CachedConstructor(Constructor c)` Constructs a `CachedConstructor` for the given Java constructor.

  - ### Methods Summary

    Methods
    Type Params | Return Type | Name and description
    --- | --- | ---
    `` | `public Object` | `doConstructorInvoke(Object[] argumentArray)` Invokes this constructor with the specified arguments after coercing them to the parameter types.
    `` | `public static CachedConstructor` | `find(Constructor constructor)` Finds a `CachedConstructor` corresponding to the specified Java constructor by searching the cached constructors of its declaring class.
    `` | `public CachedClass` | `getCachedClass()` Returns the cached class that declares this constructor.
    `` | `public Constructor` | `getCachedConstructor()` Returns the underlying Java constructor object, making it accessible if necessary.
    `` | `public Class` | `getDeclaringClass()` Returns the class that declares this constructor.
    `` | `public int` | `getModifiers()` Returns the modifiers of this constructor (e.g., public, private, protected).
    `` | `public String` | `getName()` Returns the name of the constructor (same as the declaring class name).
    `` | `protected Class[]` | `getPT()`
    `` | `public Object` | `invoke(Object[] argumentArray)` Invokes this constructor with the specified arguments.
    `` | `public boolean` | `isSynthetic()` Returns whether this constructor is synthetic (generated by the compiler).
    `` | `public String` | `toString()` Returns the string representation of this cached constructor.

  - ### Inherited Methods Summary

    Inherited Methods
    Methods inherited from class | Name
    --- | ---
    `class ParameterTypes` | `coerceArgumentsToClasses, correctArguments, getNativeParameterTypes, getPT, getParameterTypes, isValidExactMethod, isValidExactMethod, isValidMethod, isValidMethod, isVargsMethod, isVargsMethod, setParametersTypes`

- - ### Constructor Detail

    - #### public CachedConstructor(CachedClass clazz, Constructor c)

      Constructs a `CachedConstructor` for the given constructor within a cached class.

      Parameters:
        `clazz` - the cached class that declares this constructor
        `c` - the Java constructor to cache

    - #### public CachedConstructor(Constructor c)

      Constructs a `CachedConstructor` for the given Java constructor. Automatically resolves the cached class from the constructor's declaring class.

      Parameters:
        `c` - the Java constructor to cache

  - ### Method Detail

    - #### public Object doConstructorInvoke(Object[] argumentArray)

      Invokes this constructor with the specified arguments after coercing them to the parameter types.

      throws:
        GroovyRuntimeException if the invocation fails
      Parameters:
        `argumentArray` - the arguments to pass to the constructor
      Returns:
        a new instance of the class

    - #### public static CachedConstructor find(Constructor constructor)

      Finds a `CachedConstructor` corresponding to the specified Java constructor by searching the cached constructors of its declaring class.

      throws:
        RuntimeException if the constructor is not found in the cache
      Parameters:
        `constructor` - the constructor to find
      Returns:
        the cached constructor

    - #### public CachedClass getCachedClass()

      Returns the cached class that declares this constructor.

      Returns:
        the cached class

    - #### public Constructor getCachedConstructor()

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

      Returns:
        the cached constructor

    - #### public Class getDeclaringClass()

      Returns the class that declares this constructor.

      Returns:
        the declaring class

    - #### public int getModifiers()

      Returns the modifiers of this constructor (e.g., public, private, protected). See Modifier for modifier constants.

      Returns:
        the constructor modifiers

    - #### public String getName()

      Returns the name of the constructor (same as the declaring class name).

      Returns:
        the constructor name

    - #### protected Class[] getPT()

    - #### public Object invoke(Object[] argumentArray)

      Invokes this constructor with the specified arguments. Handles access control, abstract class checks, and exception wrapping.

      throws:
        GroovyRuntimeException if invocation fails, access is denied, or the class is abstract
      Parameters:
        `argumentArray` - the arguments to pass to the constructor
      Returns:
        a new instance of the class

    - #### public boolean isSynthetic()

      Returns whether this constructor is synthetic (generated by the compiler).

      Returns:
        `true` if this constructor is synthetic; `false` otherwise

    - #### public String toString()

      Returns the string representation of this cached constructor.

      Returns:
        a string representation of the underlying constructor