From 3731bd9822992f6b214df652c96b6ab55ec4bf88 Mon Sep 17 00:00:00 2001 From: Him188 Date: Wed, 18 Dec 2019 12:51:27 +0800 Subject: [PATCH] Add WeakRef --- .../src/commonMain/kotlin/net.mamoe.mirai/utils/WeakRef.kt | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/utils/WeakRef.kt b/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/utils/WeakRef.kt index b1512930c..144ca4a07 100644 --- a/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/utils/WeakRef.kt +++ b/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/utils/WeakRef.kt @@ -11,6 +11,13 @@ inline class UnsafeWeakRef(private val weakRef: WeakRef) { fun get(): T = weakRef.get() ?: error("WeakRef is released") fun clear() = weakRef.clear() + /** + * Provides delegate value. + * + * ```kotlin + * val bot: Bot by param.unsafeWeakRef() + * ``` + */ operator fun getValue(thisRef: Any?, property: KProperty<*>): T? = this.get() }