Extensions on Nullable Types and lateinit Property
Learn Kotlin’s null handling techniques through smart casting and lateinit properties.
We'll cover the following
Nullable types and extensions
Regular functions cannot be called on nullable variables. However, there is a special kind of function that can be defined such that it can be called on nullable variables. Kotlin stdlib
defines the following functions that can be called on String?
:
orEmpty
: It returns the value if it is notnull
. Otherwise, it returns an empty string.isNullOrEmpty
: It returnstrue
if the value isnull
or empty. Otherwise, it returnsfalse
.isNullOrBlank
: It returnstrue
if the value isnull
or blank. Otherwise, it returnsfalse
.
Get hands-on with 1400+ tech skills courses.