详细说明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 婚前女儿生日祝福语简短