public boolean equals(Object otherObject) {
if(this == otherObject) { // 检測this与otherObject是否引用同一个对象
return true;
} if(null == otherObject ) { // 检測otherObject是否为空
return false;
} if(!(getClass() == otherObject.getClass())){ // 比較this与oherObject是否属于同一个类,假设equal的语义在每一个子类中有所改变,就用此推断
System.out.println("-----------------getClass----------------");
return false;
} if( ! (otherObject instanceof Apple)) { // 假设语义同样就用instanceof推断,推断继承时也用到
System.out.println("------------instanceof--------------------");
return false;
} Apple other = (Apple) otherObject; // 转换为对应类型。对所需域进行推断 return name.equals(other.name)&& color.equals(other.color);
}
}

最新文章

  1. 2016.10.30 NOIP模拟赛 day2 PM 整理
  2. 编译内核实现iptables防火墙layer7应用层过滤 (三)
  3. nginx作为负载均衡服务器——测试
  4. [JAVA] java仿windows 字体设置选项卡
  5. java.util.concurrent.CopyOnWriteArrayList
  6. DBA_Oracle DBA常用SQL汇总(概念)
  7. C# and JSON
  8. 《c和指针》1.5编程练习问题
  9. git 合并两个仓库
  10. 开源中文分词工具探析(五):Stanford CoreNLP
  11. [Swift]LeetCode111. 二叉树的最小深度 | Minimum Depth of Binary Tree
  12. 修改input和textarea的placeholder的颜色,限制文本框字数输入
  13. windows系统开启虚拟化
  14. gitlab或github下fork后如何同步源的新更新内容?
  15. Unit 1 overview of IT Industry
  16. 使用nginx服务器如果遇到timeou情况时可以如下设置参数,使用fastcgi: fastcgi_connect_timeout 75; 链接 fastcgi_read_timeout 600; 读取 fastcgi_send_timeout 600; 发请求
  17. 20145332卢鑫 MSF基础应用
  18. ImageCollection
  19. ElementUI 知识点
  20. Delphi 浏览器WebBrowser

热门文章

  1. 【习题 7-2 UVA-225】Golygons
  2. Native开发与JNI机制详解
  3. 洛谷——P1012 拼数
  4. 【Unity3D自学记录】鼠标移动三维物体
  5. amazeui学习笔记二(进阶开发4)--JavaScript规范Rules
  6. docker构建一个简易镜像
  7. Mine Vison base on VC++ and procilica Gige Vison SDK
  8. MySQL主从复制之Mycat简单配置和高可用
  9. 一个DDOS病毒的分析(一)
  10. [Err] 1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''<h1 style="text-align: center;">php