Null Safety
Understand Kotlin nullable types and how the language helps prevent null-related errors.
Kotlin Code
Study the example and understand each part.
fun main() {
var name: String? = "Vincent"
println(name)
name = null
println(name)
println(name?.length)
}
Kotlin is commonly developed using Android Studio or IntelliJ IDEA. These examples can be used as a foundation for Android application development.
Key Concept
Kotlin's null-safety system uses nullable types such as String? to make possible null values explicit.
Expected Output / Result
Vincent null null
Finished this lesson?
Mark it complete to update your course progress.