Nullable vs Non-Null Types
The ? type marker.
Why Null Safety Matters
Many crashes in Android apps come from one mistake: using a value that is actually missing. In other languages this becomes a dreaded NullPointerException at runtime.
Kotlin tackles this at compile time. The type system tracks which values may be null and which never can. This lesson introduces the foundation of that system.
Non-Null Types
By default, a Kotlin type cannot hold null. A String always points to a real string.
If you try to assign null to it, the code will not even compile. This is the safe default.
fun main() {
val name: String = "Ada"
println(name.length)
}All lessons in this course
- Nullable vs Non-Null Types
- Safe Calls and Elvis
- let, also, and Scope Functions
- Avoiding NullPointerExceptions