Nullable and Non-Null Types
The type system basics.
Why Null Safety Matters
The infamous NullPointerException has crashed countless programs. Kotlin tackles this problem head-on by making nullability part of the type system.
In Kotlin, the compiler knows whether a value can be null or not, and it forces you to handle the possibility before you run into trouble.
Non-Null Types
By default, every type in Kotlin is non-null. A variable of type String can never hold null.
This guarantee is enforced at compile time, so you can use the value freely without checks.
fun main() {
val name: String = "Alice"
println(name.length)
}All lessons in this course
- Nullable and Non-Null Types
- Safe Calls and Elvis
- The !! Operator
- Platform Types