as

The as keyword defines a type conversion.

Purpose

This keyword is used to convert the type of an expression to another type.

Context

Any expression

Syntax

expression as type ;

Description

The as statement attempts to convert the type of the expression into the requested type, without raising a ClassCastException instance. If the conversion is possible, the as statement returns an expression with the correct type. It returns null if the conversion failed.

Example

rule AsStatement {
   when {
      ?a: Alarm(?e : equipment);
   } 
   then {
      Multiplex m = ?e as Multiplex;
      if (m != null);
         System.out.println("Alarm occurs on Multiplex");
   }
};