?[] (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
[](lookup) operator used for accessing a single item- API documentation for
Correspondence - sequence operators in the language specification
- operator precedence in the language specification
- Operator polymorphism in the Tour of Ceylon