The Java interface / Advanced programming |
When manipulating an object reference with a variable defined with a superclass of the real class used to instantiate the object, you sometimes need to identify the real class of the object.
This is possible with the INSTANCEOF operator.
object_reference INSTANCEOF type_or_class
IMPORT JAVA java.lang.Object IMPORT JAVA java.lang.StringBuffer MAIN DEFINE o java.lang.Object LET o = StringBuffer.create() DISPLAY o INSTANCEOF StringBuffer -- Shows 1 (TRUE) END MAIN