main.reflection.kType.kt Maven / Gradle / Ivy
package de.peekandpoke.ultra.common.reflection
import kotlin.reflect.KClass
import kotlin.reflect.KType
import kotlin.reflect.KTypeProjection
import kotlin.reflect.full.createType
import kotlin.reflect.typeOf
/**
* Creates a [TypeRef] from the given class [T]
*
* The given type [T] must not be generic, otherwise an exception will be thrown
*/
inline fun kType(): TypeRef {
val type: KType = typeOf()
return TypeRef.createForKType(type = type)
}
/**
* Creates a [TypeRef] from the given [Class]
*/
fun Class.kType(): TypeRef = kotlin.kType()
/**
* Creates a [TypeRef] from the given [KClass]
*/
fun KClass.kType(): TypeRef = TypeRef.createForKClass(cls = this, nullable = false)
/**
* Creates a [TypeRef] for a List type of the given type
*/
inline fun kListType(): TypeRef> = kType().list
/**
* Creates a [TypeRef] for a Map type with the given [KEY] and [VAL] types
*/
inline fun kMapType(): TypeRef
© 2015 - 2024 Weber Informatics LLC | Privacy Policy