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.


void m(Anything obj) {
    Object|Null maybeNull = obj of Object|Null;


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.


The of operator is primitive.


The of operator is not polymorphic.


The result type of the of operator is of the given type.


  • 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