Make weak reference work only on non-nullable types. (#1496)

This commit is contained in:
Nikolay Igotti
2018-04-13 15:26:44 +03:00
committed by GitHub
parent 52d0e47999
commit c97124ea60
+2 -3
View File
@@ -21,13 +21,12 @@ package konan.ref
* retrieve a strong reference to an object, or return null, if object was already destoyed by
* the memory manager.
*/
class WeakReference<T> {
class WeakReference<T : Any> {
/**
* Creates a weak reference object pointing to an object. Weak reference doesn't prevent
* removing object, and is nullified once object is collected.
*/
constructor(referred: T) {
if (referred == null) throw Error("Weak reference to null?")
pointer = getWeakReferenceCounter(referred)
}
@@ -49,4 +48,4 @@ class WeakReference<T> {
* Returns either reference to an object or null, if it was collected.
*/
@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?