Language assistance for weak property


#1

It feels like a new language should provide simplification of implementing a weak reference field. Currently, it seems like I must do something like this to have a WeakReference field that is settable from the outside:

class c {
    var delegate: WeakReference<X>? = null
    fun setDelegate(delegate: X) {
        this.delegate = WeakReference(delegate)
    }
    // if you need (maybe you don't)
    fun getDelegate(): X? = delegate?.get()
}

#2

Have you looked at delegated properties? That probably fills your needs.