关于instanceof
做了下面2个测试:
(1)
Integer n = new Integer(3);
boolean bo3 = n instanceof Integer;
System.out.println(bo3);
这样打印出来是true
(2)
Integer n = new Integer(3);
boolean bo3 = n instanceof String;
System.out.println(bo3);
这样,我认为应该打印出false
但是编译的时候报错了:
Incompatible conditional operand types Integer and String
说Integer 和 String有矛盾!
但是我认为打印出来应该是false才对!
不知道boolean bo3 = n instanceof String;这句话为什么编译会提示那样的错误?
谢谢!