Ankur Gupta
08/07/2019, 4:31 AMclass TeaMaker {
private lateinit var tea: Tea
fun prepareTea() {
tea = Tea()
}
fun addSugar() {
tea.add(Sugar())
}
}
class Restaurant {
...
//In some method
val teaMaker = TeaMaker()
teaMaker.prepareTea()
teaMaker.addSugar()
}
The problem is when i call addSugar I get the lateinit not initialized exception. I tried setting up debugger but found it is initialised. Am I missing something?arekolek
08/07/2019, 6:00 AMteaMaker.prepareTea()
teaMaker.addSugar()
really done sequentially, or are there multiple threads? If there are, it could explain why the problem goes away when you attach debuggerDico
08/07/2019, 6:39 PMTea()
returned null
lateinit
property is not fail-safe in this case and results in wrong error!!
and see if error changesBrandon Ward
08/16/2019, 2:43 PMvoid
/ unit
return type, so I highly doubt !!
will change anything.Dico
08/16/2019, 5:39 PMtea = Tea()!!
Ankur Gupta
08/18/2019, 7:44 AM