ReflectionUtils

Functions

Link copied to clipboard
fun <T : Any> classForName(name: String): Validated<Throwable, KClass<T>>

Safely gets the class with this name wrapped in a Validated. The throwable will be of type ClassNotFoundException or ClassCastException if T is not assignable from the class.

Link copied to clipboard
inline suspend fun <T : Any> clone(obj: T, replaceProperties: Map<KProperty1<T, *>, Any> = emptyMap()): T

Reads the properties of an instance through reflection, and constructs a new instance of the same type. If this class contains immutable properties that cannot be changed through reflection these cannot be cloned and will be ignored.

Link copied to clipboard
@ApiStatus.Experimental
@ApiStatus.AvailableSince(value = "5.0.0")
fun <F : Any, T : Any> typeArgumentOf(obj: F, fromSupertype: KClass<F>, index: Int): KClass<T>

Searches for the type argument of the given class that was supplied to the given super class.