INSTANCEOF
The INSTANCEOF
checks
the class of an object.
Syntax
expr INSTANCEOF type
- expr can be any expression supported by the language.
- type is a structured user defined type or a Java class.
Usage
TheINSTANCEOF
operator
evaluates to TRUE
if the object reference
is of the type or class specified.The INSTANCEOF
operator
is used to check if an expression (usually, an object reference)
is one of the type or class specified by type.
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