Make weak reference work only on non-nullable types. (#1496)
This commit is contained in:
@@ -21,13 +21,12 @@ package konan.ref
|
|||||||
* retrieve a strong reference to an object, or return null, if object was already destoyed by
|
* retrieve a strong reference to an object, or return null, if object was already destoyed by
|
||||||
* the memory manager.
|
* the memory manager.
|
||||||
*/
|
*/
|
||||||
class WeakReference<T> {
|
class WeakReference<T : Any> {
|
||||||
/**
|
/**
|
||||||
* Creates a weak reference object pointing to an object. Weak reference doesn't prevent
|
* Creates a weak reference object pointing to an object. Weak reference doesn't prevent
|
||||||
* removing object, and is nullified once object is collected.
|
* removing object, and is nullified once object is collected.
|
||||||
*/
|
*/
|
||||||
constructor(referred: T) {
|
constructor(referred: T) {
|
||||||
if (referred == null) throw Error("Weak reference to null?")
|
|
||||||
pointer = getWeakReferenceCounter(referred)
|
pointer = getWeakReferenceCounter(referred)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -49,4 +48,4 @@ class WeakReference<T> {
|
|||||||
* Returns either reference to an object or null, if it was collected.
|
* Returns either reference to an object or null, if it was collected.
|
||||||
*/
|
*/
|
||||||
@Suppress("NON_PUBLIC_CALL_FROM_PUBLIC_INLINE")
|
@Suppress("NON_PUBLIC_CALL_FROM_PUBLIC_INLINE")
|
||||||
public inline fun <reified T> WeakReference<T>.get() = pointer?.get() as T?
|
public inline fun <reified T : Any> WeakReference<T>.get() = pointer?.get() as T?
|
||||||
|
|||||||
Reference in New Issue
Block a user