instanceof
来源:互联网 发布:java常用数据结构 编辑:程序博客网 时间:2024/06/06 01:51
1,instanceof为一个表达式运算符。是判断前者是否是后者的一个实例。
如:Animal animal=new Bird();
if(animal instanceof Dog){
System.out.println("animal is Dog");
}else{
System.out.println("animal is not Dog");
}
是判断animal这个对象是否是属于Dog这个类的一个实例。
Animal为接口。Bird类和Dog类都继承Animal。
如:public interface Animal {
public String getValue();
}
public class Bird implements Animal{
public String getValue() {
// TODO Auto-generated method stub
return "Bird";
}
}
public class Dog implements Animal{
public String getValue() {
// TODO Auto-generated method stub
return "Dog";
}
}
如:Animal animal=new Bird();
if(animal instanceof Dog){
System.out.println("animal is Dog");
}else{
System.out.println("animal is not Dog");
}
是判断animal这个对象是否是属于Dog这个类的一个实例。
Animal为接口。Bird类和Dog类都继承Animal。
如:public interface Animal {
public String getValue();
}
public class Bird implements Animal{
public String getValue() {
// TODO Auto-generated method stub
return "Bird";
}
}
public class Dog implements Animal{
public String getValue() {
// TODO Auto-generated method stub
return "Dog";
}
}
阅读全文
0 0
- instanceof?
- instanceof
- instanceof
- instanceof
- instanceof
- instanceof
- instanceof
- instanceof
- instanceof
- instanceof
- instanceof
- instanceof
- instanceof
- instanceof
- instanceof
- instanceof
- instanceof
- instanceof
- http协议
- Python爬虫之分布式爬虫
- input的title属性
- RandomAccess接口使用
- HttpClient post请求调取接口 例子
- instanceof
- (spring boot)maven 打包war 部署到tomcat
- openstack虚机流量监控demo
- C#使用INI进行数据保存
- loadrunner常用配置和常见问题
- Spark集群部署
- 揭秘:Python为什么这么火,高中生都要学?
- android购物车的操作
- 程序员中的老司机们,30 后的路该开向哪里?