instanceof 如何使用
来源:百度知道 编辑:UC知道 时间:2024/09/25 08:33:21
貌似只能比较 "" instanceof String 啊
我用 1 instanceof int , false instanceof boolean 都不行啊
自己建的类 a instanceof b 也提示 红线错误
我用 1 instanceof int , false instanceof boolean 都不行啊
自己建的类 a instanceof b 也提示 红线错误
int boolean 是值数据类型
而instanceof 只能 用于 对象 类型
例如
正确:
Integer i;
if(i instanceof Integer)
System.out.println("i 是 Integer类型");
错误:
int i;
if(i instanceof int)
System.out.println("i 是 int类型");