b
Ideas?
k
Don't know about the exception, but wouldn't it be easier and safer to just make the field nullable?
b
sure 🙂 I thought this trick was a bit better with "isInitialized" it makes the code's intention clear
k
I disagree: I think
lateinit
should be reserved for things like DI frameworks or Beans-type builders.
1
1
::isInitialized
is for really exceptional situations.
b
I don't know, in my case, it's pretty much what lateinit is intended for. It's normally not null (except when it was not yet initialized). I'd say this is not an unreasonable usecase for it.
g
I would agree with Karel, that you shouldn't use isInotialized in your case, it doesn't looks reasonable. Looks that your case is Android, so you should check lifecycle implementation of your component and use lateinit (it's actually good use case of lateinit for Android components because classes managed by the system and you cannot use constructor) or use nullable
b
Thanks for your input, but really that was not the point of my question 😛
independently of whether it's a good idea to do this, it should work (IMHO?)
👌 1
k
That's true of course.
👍 1