instanceof 运算符是用来在运行时指出对象是否是特定类的一个实例。instanceof通过返回一个布尔值来指出,这个对象是否是这个特定类或者是它的子类的一个实例。
用法:
result = object instanceof class
例如:
Boolean b;
String str = "foo";
b = ( str instanceof String ); // true
b = ( str instanceof Object ); // also true
b = ( str instanceof Date ); // false, not a Date or subclass
String s = null;
if ( s instanceof String )
// false, won't happen
if ( foo instanceof byte[] )