Promote KClass.cast/safeCast, KAnnotatedElement.hasAnnotation() to stable
This commit is contained in:
@@ -20,7 +20,8 @@ inline fun <reified T : Annotation> KAnnotatedElement.findAnnotation(): T? =
|
||||
/**
|
||||
* Returns true if this element is annotated with an annotation of type [T].
|
||||
*/
|
||||
@ExperimentalStdlibApi
|
||||
@SinceKotlin("1.3")
|
||||
@SinceKotlin("1.4")
|
||||
@Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE")
|
||||
@WasExperimental(ExperimentalStdlibApi::class)
|
||||
inline fun <reified T : Annotation> KAnnotatedElement.hasAnnotation(): Boolean =
|
||||
findAnnotation<T>() != null
|
||||
|
||||
@@ -19,8 +19,8 @@ import kotlin.internal.LowPriorityInOverloadResolution
|
||||
* @see [KClass.isInstance]
|
||||
* @see [KClass.safeCast]
|
||||
*/
|
||||
@SinceKotlin("1.3")
|
||||
@ExperimentalStdlibApi
|
||||
@SinceKotlin("1.4")
|
||||
@WasExperimental(ExperimentalStdlibApi::class)
|
||||
@LowPriorityInOverloadResolution
|
||||
fun <T : Any> KClass<T>.cast(value: Any?): T {
|
||||
if (!isInstance(value)) throw ClassCastException("Value cannot be cast to $qualifiedOrSimpleName")
|
||||
@@ -39,8 +39,8 @@ internal expect val KClass<*>.qualifiedOrSimpleName: String?
|
||||
* @see [KClass.isInstance]
|
||||
* @see [KClass.cast]
|
||||
*/
|
||||
@SinceKotlin("1.3")
|
||||
@ExperimentalStdlibApi
|
||||
@SinceKotlin("1.4")
|
||||
@WasExperimental(ExperimentalStdlibApi::class)
|
||||
@LowPriorityInOverloadResolution
|
||||
fun <T : Any> KClass<T>.safeCast(value: Any?): T? {
|
||||
return if (isInstance(value)) value as T else null
|
||||
|
||||
Reference in New Issue
Block a user