invoke

open fun invoke(args: Array<Any?> = emptyArray<Any?>()): T

Invokes the constructor with the specified arguments to create a new instance. Uses FastInvoke.safeNewInstance for proper exception handling and performance.

Return

a new instance of type T

Parameters

args

the arguments to pass to the constructor (empty array by default)

Throws

if the constructor invocation fails or throws an exception

Example usage:

val constructor = MyClass::class.java.getConstructor(String::class.java)
val accessor = DefaultConstructorAccessor(constructor)
val instance = accessor.invoke(arrayOf("initial value"))