# Variant

The standard library contains the type `core.Variant` that represents an object of any type in the system. Due to the need to accommodate any type, it has to allocate values on the heap rather than internally. This means that using a `Variant` incurs a performance penalty over situations where the types are known statically.

The `Variant` has no facility to extract the current value in a safe manner. It is necessary to use weak casts to extract the contained type.

The `Variant` contains constructors that automatically cast any types into a `Variant` implicitly. This allows functions that accept `Variant`s to be used conveniently.

Apart from the constructors, the `Variant` has the following members:

- `init()`

  Create an empty variant.

- `core.Bool empty()`

  Is the variant empty?

- `core.Bool any()`

  Does the variant contain any element?

- `core.Bool has(core.lang.Type type)`

  Does this variant contain the type `type`?

- `core.Maybe<core.lang.Type> type()`

  Get the type of the value in the variant. Returns `null` if it is empty.

It is also possible to print variants using `<<` or `toS` as usual.