I discovered the powerful keyword lateinit. Using lateinit, Kotlin allows you to initialize non-null properties after the constructor has been called, so I am moving away from null properties all together.
Lessons learned while converting to Kotlin with Android Studio
Benjamin Baxter

From the documentation about lateinit:

Accessing a lateinit property before it has been initialized throws a special exception that clearly identifies the property being accessed and the fact that it hasn't been initialized.

So isn’t this essentially removing the NPE for a another exception that’s almost the same as a NPE? I’ve used lateinit when it’s being handle by DI or if it’s being set in the onCreate but I use it sparingly and opt for let in most situations now.

Like what you read? Give Cody Engel a round of applause.

From a quick cheer to a standing ovation, clap to show how much you enjoyed this story.