Skip to content
Commitwise
Menu

Null safety

Also called: Optionals, Nullable types

A language feature that makes the compiler check where a value might be missing, so you can't use it by accident.

Definition

In a null-safe language, the type of a variable says whether it can be empty. Swift calls these optionals (String?), Kotlin calls them nullable types (String?), and Java has the Optional<T> wrapper plus annotations. Before you use a value that might be missing, the compiler makes you handle the empty case, which removes a whole class of crashes.

In practice

A user profile has an optional middle name. In Swift, user.middleName.count does not compile until you unwrap it, for example with user.middleName?.count ?? 0.

Learn it in context

Lessons that use this term.

Related terms

Esc

Type to search the whole site.