在Java中的instanceof运算符
该运算符仅用于对象引用变量。该运算符检查对象是否属于特定类型(类类型或接口类型)。 instanceof 运算符写为 -
( Object reference variable ) instanceof (class/interface type)登录后复制
示例
现场演示
public class Test { public static void main(String args[]) { String name = "James"; // following will return true since name is type of String boolean result = name instanceof String; System.out.println( result ); } }登录后复制