Add WeakRef

This commit is contained in:
Him188 2019-12-18 12:51:27 +08:00
parent eb9a64e5a0
commit 3731bd9822

View File

@ -11,6 +11,13 @@ inline class UnsafeWeakRef<T>(private val weakRef: WeakRef<T>) {
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()
}