Kotlin Q & A
What is a nullable type in Kotlin?
In Kotlin, a nullable type is a type that can hold a null value in addition to its regular values. By default, Kotlin’s type system is designed to prevent null pointer exceptions (NPEs) by requiring variables to be explicitly marked as nullable or non-nullable.
To declare a nullable type, you append a question mark (?) to the type declaration. For example:
Kotlin
var nullableString: String? = null
Here, nullableString is declared as a nullable string type, which means it can either hold a valid string value or be null. This declaration allows developers to represent the absence of a value in a type-safe manner, reducing the risk of NPEs.
Previously at
Experienced Android Engineer specializing in Kotlin with over 5 years of hands-on expertise. Proven record of delivering impactful solutions and driving app innovation.