详细说明Java中的operator实例的合法操作数?
Java中的instanceof运算符用于查找引用是Type的实例(即类还是接口)。
示例
public class InstanceOfExample {
public static void main(String args[]) {
String str = "hello";
boolean bool = str instanceof String;
System.out.println(bool);
}
}输出结果
true
实例运算符的合法操作数
以下是instanceof运算符的唯一合法操作数-
左操作数-它必须是代表对象的引用。
右操作数-它必须是Java类或接口的名称。
如果不使用这两个操作数,则将生成编译时错误。
public class InstanceOfExample {
public static void main(String args[]) {
int i =20;
boolean bool = i instanceof String;
System.out.println(bool);
}
}编译时错误
InstanceOfExample.java:4: error: unexpected type
boolean bool = i instanceof String;
^
required: reference
found: int
1 error热门推荐
10 庆祝国家的祝福语简短
11 生日祝福语舅舅 简短独特
12 五一祝福语大全简短最新
13 哥哥祝福语简短霸气句子
14 老公生日祝福语简短好看
15 新年简单祝福语简短好看
16 下雪路滑祝福语简短
17 汤姆猫祝福语简短霸气
18 生了女孩祝福语简短的