Optional


Object Hierarchy:

Object hierarchy for Optional

Description:

public class Optional<T> : Object

A container object that may or may not contain a value.

Optional is a type-safe alternative to null. Instead of returning null, methods can return Optional to explicitly indicate that a value may be absent. Inspired by Java's Optional, OCaml's option, and Rust's Option.

Example:

    var opt = Optional.of<string> ("hello");
assert (opt.isPresent ());
assert (opt.get () == "hello");

var empty = Optional.empty<string> ();
assert (empty.isEmpty ());
assert (empty.orElse ("default") == "default");


Namespace: Vala.Collections
Package: Valacore

Content:

Static methods:

Methods:

Inherited Members:

All known members inherited from class GLib.Object