?[] (null-safe lookup) operator

The null-safe lookup operator accesses an element in a Correspondence? if that operand is not null, otherwise results in null.

Usage

void m(String[]? seq) {
    String? first = seq?[0];
}

Description

Definition

The ?[] operator is defined as follows:

if (exists lhs) lhs[index] else null    

See the language specification for more details.

Polymorphism

The ?[] operator is polymorphic. The meaning of ?[] depends on the Correspondence interface.

See also