INSTANCEOF

The INSTANCEOF checks the class of an object.

Syntax

variable INSTANCEOF class 
  1. variable is a variable referencing a Java object.
  2. class is a Java class.

Usage

The INSTANCEOF operator evaluates to TRUE if the object reference is of the specified class.

Example

IMPORT JAVA java.lang.Object 
IMPORT JAVA java.lang.StringBuffer 
IMPORT JAVA java.lang.Number 
MAIN
  DEFINE o java.lang.Object 
  DEFINE sb java.lang.StringBuffer 
  LET sb = StringBuffer.create()
  LET o = sb 
  DISPLAY sb INSTANCEOF java.lang.StringBuffer  -- shows 1
  DISPLAY o INSTANCEOF java.lang.StringBuffer   -- shows 1
  DISPLAY o INSTANCEOF java.lang.Number         -- shows 0
END MAIN