instanceof

The instanceof keyword tests whether an expression can be cast into a type.

Purpose

This keyword is used in the condition part or in the action part of rules and in functions to test whether an expression can be cast into a referenced type.

Context

Any expression

Syntax

[?var:] className (expression instanceof type) 

Description

Use the instanceof operator in the condition part or in the action part of rules and in functions to test whether the passed expression (an operand of instanceof) can be cast into the passed type (another operand of instanceof) without raising a ClassCastException exception. If the expression is passed successfully, this test returns true. It returns false if the test is unsuccessful.

Example

rule InstanceofTest {
   when {
      ?a: Alarm(equipment instanceof Multiplex);
   }
   then {
      System.out.println("Alarm occurs on Multiplex");
   }
};