# createInstance

@ JvmOverloads
fun < T : Any > Class < T >. createInstance (vararg args: Any ?, isPublic: Boolean = true): T

Create an instance of Class with the given arguments.

- Note: If you give a null argument, it will be treated as an any type value for the constructor parameter, but if all arguments are null, it will throw an IllegalStateException.

#### Receiver

the Class to be instantiated.

#### Return

T

#### Parameters

args

the arguments to be passed to the constructor.

isPublic

whether to only consider public constructors, default is true.

#### See also

createInstanceOrNull
createInstanceAsType
createInstanceAsTypeOrNull

#### Throws

NoSuchMethodException

if no suitable constructor is found.

IllegalStateException

if all arguments are null.

fun < T : Any > KClass < T >. createInstance (vararg args: Any ?, isPublic: Boolean = true): T

Create an instance of KClass.java with the given arguments.

#### See also

createInstance