; using instanceof to test for a String:
aload_1 ; push object reference in local variable 1 onto stack
instanceof java/lang/String; ; test if item on stack is a String
ifne HaveString ; if so, goto HaveString
return ; otherwise, return
HaveString:
; if this point is reached, local variable 1 holds a string
; this example uses instanceof to test if local variable 1 holds
; an integer array
aload_1 ; push local variable 1 onto the stack
instanceof [I ; test if the top item on the stack is an integer array
ifne HaveIntegerArray ; if so, jump to HaveIntegerArray
return ; simply return if local variable 1 is not an int array
HaveIntegerArray:
; if this point is reached, local variable 1 holds an integer array
; you can also use instanceof to test that objects implement a given interface,
; e.g.
aload_1 ; push local variable 1 onto the stack
instanceof java/lang/Runnable ; test if it implements the Runnable interface
ifne HaveARunnable ; if so, jump to HaveARunnable
return ; otherwise return
HaveARunnable:
; if this point is reached, local variable 1 holds a reference to an object
; that implements the Runnable interface.