https://kotlinlang.org logo
Title
j

johannes.lagos

02/27/2017, 11:41 AM
Hi. How it is the proper way to init a weak reference on Kotlin?
r

ross_a

02/27/2017, 12:02 PM
johannes.lagos: val reference = WeakReference<String>("A”) ?
j

johannes.lagos

02/27/2017, 12:03 PM
Should it work better with a lateinit?
r

ross_a

02/27/2017, 12:06 PM
I don’t quite understand, lateinit is used to declare a var which has looser null safety checks - as in, you don’t have to use ?/!! all the time but it should be assigned by the time you use it or it’ll immediately error
If you want to reload the value on access time if it’s been GC’d, then you could probably do something neat with a delegate? Not quite sure your use case tho
j

johannes.lagos

02/27/2017, 12:19 PM
The use case it have a reference to a view interface on a presenter