newInstance

@NotNull
open fun <T> newInstance(@NotNull constructor: Constructor<T>, args: Array<Any>): T

Creates a new instance of the class using the specified constructor with the given arguments.

This method provides a type-safe wrapper around newInstance while avoiding the performance penalty of the spread operator.

example

Constructor<MyClass> constructor = MyClass.class.getConstructor(String.class);
MyClass instance = FastInvoke.newInstance(constructor, new Object[]{"initial value"});

Return

a new instance of the class; never null

Parameters

constructor

the constructor to use for instantiation; must not be null

args

the arguments to pass to the constructor; may be null if the constructor takes no arguments

<T>

the type of the instance to create

Throws

if the constructor throws an exception

if the class cannot be instantiated (e.g., abstract class, interface)

if the constructor is not accessible

if the arguments are not appropriate for the constructor