Java的操作符instanceof的使用和注意点

来源:互联网 发布:飞鱼打印软件 编辑:程序博客网 时间:2024/05/17 07:24

instanceof操作符是用于java运行时指出对象是否某一特定类的实例.但是用在java的引用数据类型作判断的时候要注意包装类的问题,如下:


System.out.println(new Integer(100));


System.out.println(new Integer(100) instanceof Integer);


 /*System.out.println(100 instanceof Integer);*/  //编译有误
 /*System.out.println(true instanceof Boolean);*/ //编译有误


 System.out.println(new Boolean(true) instanceof Boolean);