Commit aebaf605 authored by Him188's avatar Him188

Fix weakRef

parent 6bfd11b0
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
package net.mamoe.mirai.utils package net.mamoe.mirai.utils
import kotlin.properties.ReadOnlyProperty
import kotlin.reflect.KProperty import kotlin.reflect.KProperty
/** /**
...@@ -18,7 +19,13 @@ inline class UnsafeWeakRef<T>(private val weakRef: WeakRef<T>) { ...@@ -18,7 +19,13 @@ inline class UnsafeWeakRef<T>(private val weakRef: WeakRef<T>) {
* val bot: Bot by param.unsafeWeakRef() * val bot: Bot by param.unsafeWeakRef()
* ``` * ```
*/ */
operator fun getValue(thisRef: Any?, property: KProperty<*>): T = this.get() operator fun provideDelegate(thisRef: Any?, property: KProperty<*>): ReadOnlyProperty<Any?, T> {
return object : ReadOnlyProperty<Any?, T> {
override fun getValue(thisRef: Any?, property: KProperty<*>): T {
return get()
}
}
}
} }
/** /**
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment