描述:
instanceof是Java、php的一个二元操作符(运算符),和==,>,<是同一类东西。由于它是由字母组成的,所以也是Java的保留关键字。
它的作用是判断其左边对象是否为其右边类的实例,返回boolean类型的数据。
用法:
boolean result = object instanceof class
参数类型
public static void main(String[] args) {
boolean bool = false;
int b =2;
add("see",b);
}
public static void add(final String name, final Object value){
if((value instanceof Boolean)){
System.out.println("boolean 类型");
}
else if(value instanceof String){
System.out.println("String 类型");
}else if(value instanceof Integer){
System.out.println("Integer 整形");
}
else{
System.out.println("其他类型");
}
}
}