首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > 编程 >

重温java核心技术,equals步骤实现建议

2012-11-05 
重温java核心技术,equals方法实现建议1、显式参数命名为otherObject,稍后要将它转换为叫other的变量;?2、检

重温java核心技术,equals方法实现建议

1、显式参数命名为otherObject,稍后要将它转换为叫other的变量;

?

2、检测this和otherObject是否是同一个变量,if(this==ohterObject) return true;

?

3、检测otherObject是否为null,如果为null,则返回false;

?

4、比较this和otherObject是否属于同一个类,if(getClass()!=otherObject.getClass()) return false;

?

5、将otherObject转换为相应的类的类型变量,ClassName other = (ClassName)otherObject;

?

6、开始对所有需要比较的field进行比较。

热点排行