open static fun <T : Any> instantiateClass(clazz: Class<T>): T
Instantiate a class using its no-arg constructor.
Note that this method tries to set the constructor accessible if given a non-accessible (that is, non-public) constructor.
BeanInstantiationException - if the bean cannot be instantiated
Return
the new instance
See Also
Constructor#newInstance
open static fun <T : Any> instantiateClass(clazz: Class<*>, assignableTo: Class<T>): T
Instantiate a class using its no-arg constructor and return the new instance as the specified assignable type.
Useful in cases where the type of the class to instantiate (clazz) is not available, but the type desired (assignableTo) is known.
Note that this method tries to set the constructor accessible if given a non-accessible (that is, non-public) constructor.
assignableTo - type that clazz must be assignableTo
BeanInstantiationException - if the bean cannot be instantiated
Return
the new instance
See Also
Constructor#newInstance
open static fun <T : Any> instantiateClass(ctor: Constructor<T>, vararg args: Any): T
Convenience method to instantiate a class using the given constructor.
Note that this method tries to set the constructor accessible if given a non-accessible (that is, non-public) constructor, and supports Kotlin classes with optional parameters and default values.
ctor - the constructor to instantiate
args - the constructor arguments to apply (use null for an unspecified parameter if needed for Kotlin classes with optional parameters and default values)
BeanInstantiationException - if the bean cannot be instantiated
Return
the new instance
See Also
Constructor#newInstance