Browse topics
Kotlin Intermediate
Null Safety
Nullable types, safe casts, let, lateinit and null handling in Kotlin.
null safetyNullable Types in KotlinKotlin types are divided into nullable and non-nullable types. A Kotlin example with source code and sample output.null safetySafe Cast Operator (as?) in KotlinThe safe cast operator as? tries to cast a value to another type. A Kotlin example with source code and sample output.null safetylet Function for Null Safety in KotlinThe let function executes a block only when the object is not null. A Kotlin example with source code and sample output.null safetyalso Operator for Null Handling in Kotlinalso performs an action on an object and returns the object itself. A Kotlin example with source code and sample output.null safetylateinit and Nullable Properties in Kotlinlateinit is used for non-nullable var properties that are initialized later. A Kotlin example with source code and sample output.null safetyElvis Operator for Default Values in KotlinThe Elvis operator ?: returns the left value when it is not null. A Kotlin example with source code and sample output.null safetySmart Casts in KotlinAfter an is check, the compiler automatically casts the variable to the subtype. A Kotlin example with source code and sample output.
Related topics
Kotlin Strings String basics, templates, comparison, substring and raw strings. Kotlin Arrays Declare, initialize, access and iterate arrays in Kotlin. Collections Intro Lists, sets, maps and common collection operations. Packages & Imports Organize code with packages, imports and visibility modifiers. Exception Handling try-catch, finally, throw, custom exceptions and try expressions. Type Features Type aliases, destructuring declarations and related Kotlin type syntax.