nativeMain.io.github.vinccool96.ref.WeakReferenceFactory.kt Maven / Gradle / Ivy
package io.github.vinccool96.ref
actual object WeakReferenceFactory {
actual fun createWeakRef(referent: T): WeakReference {
return NativeCoreWeakRef(referent)
}
class NativeCoreWeakRef(referent: T) : WeakReference {
private val ref = kotlin.native.ref.WeakReference(referent as Any)
override val value: T?
get() = this.get()
@Suppress("UNCHECKED_CAST")
override fun get(): T? {
this.ref.value
return this.ref.get() as T?
}
override fun clear() {
this.ref.clear()
}
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy