DEV Community

Discussion on: Safely accessing lateinit properties in Kotlin

Collapse
 
rahulchowdhury profile image
Rahul Chowdhury 🕶

Hey Giorgos, this might not be the best way to approach the "empty state" issue but it's certainly a neat trick that you can apply using the Kotlin standard library.

How you approach the problem and architect your application differs from person to person, isn't it?

This is just one way of doing it. :-)

Collapse
 
neokleoys2005 profile image
Giorgos Neokleous

Of course it depends on the person and the team. I think you shouldn't put the label

Taking the rookie approach

For wrapping properties with is not null conditions. On runtime the null check is theoretically faster than the approach described above.

Another way of solving it, it's to design the application in such way that race condition doesn't happen. Try and access the property when and only when is initialised and not before that. So that you avoid such issues.