DEV Community

Cover image for lateinit vs nullable type | KnowYourKotlin
Chetan garg
Chetan garg

Posted on • Updated on • Originally published at

lateinit vs nullable type | KnowYourKotlin

Hi #androidDevs, This is Androidbites where I try to break down a small concept into an understandable code snippet and share my learning experience with it.

Today's topic is related to handling nullability using lateinit modifier, I absolutely agree null is the Billion dollar problem in a programming language, and for you, as a developer, it's your responsibility that your app doesn't fall in as a victim of it and not crash your app due to that, In kotlin there are many languages functionalists build in that enable you to aware of null happening code and ask you to cater them properly.

Lateinit is one of those tools, the solution of a problem is not to create that problem right? Similarly instead of having a nullable type just replace it with non-null type? right 🧐? an obvious solution, 

let's dig deeper with the snippet below, 👁 on the code 💻.

Alt Text

if you like to know more on the same topic read the complete article on

👉 AndroidBites|lateinit-vs-null

Hope to see you on the other side...

Until next time. Happy Hacking! 👩‍💻

Stalk Me 👀 :
LinkedIn | Medium | Twitter | StackOverflow | CodeWars |WorkX |Github |Instagram |Youtube

Discussion (0)