INSTANCEOF
The INSTANCEOF
checks
the class of an object.
Syntax
variable INSTANCEOF class
- variable is a variable referencing a Java object.
- class is a Java class.
Usage
TheINSTANCEOF
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