I'm trying to make a singleton in Kotlin and am running into problems because I get a smart cast to PresenterManager is impossible because instance is mutable property that could have been changed at this time
.
This seems like a pretty standard way to make a singleton. Why won't it let me and how can I fix it?
PresenterManager {
//some code
....
companion object {
private val PRESENTER_ID = "presenter_id"
private var instance: PresenterManager? = null
fun getManager(): PresenterManager {
if (instance == null) {
instance = PresenterManager(10, 30, TimeUnit.SECONDS)
}
return instance
}
}
}