Note: information on this page refers to Ceylon 1.1, not to the current release.
of
operator
The non-associating, binary infix of
operator is used to cast
the type of an expression, when this can be statically proven to
be safe.
Usage
void m(Anything obj) {
Object|Null maybeNull = obj of Object|Null;
}
Description
According to the language specification, the of
operator:
... narrows or widens the type of an expression to any specified type that covers the expression type.
Definition
The of
operator is primitive.
Polymorphism
The of
operator is not polymorphic.
Type
The result type of the of
operator is of the given type.
Note
- This is not an unsafe typecasting operator familiar in most other
programming languages. If an expression involving
of
is accepted by the compiler, it will never result in a typing exception at runtime.
See also
- Coverage in the language specification