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