首页 > 其他 > 详细

以上过程为实现equals的标准过程

时间:2018-08-04 18:27:40      阅读:144      评论:0      收藏:0      [点我收藏+]

以下为定义equal(加上这个定义,返回ture或false)

public boolean equals(Object o){

 student s=(student)o;

 if (s.name.equals(this.name)&&s.age==this.age)

else return false;

}如果equals()返回的值为

 

以下为实现标准equals的流程:

public boolean equals(Object o){

 if (this==o) return trun; //此时两者相同

 if (o==null) return false;

 if (! o instanceof strudent) return false; //不同类

 studeng s=(student)o; //强制转换

  if (s.name.equals(this.name)&&s.age==this.age) return true;

else return false;

}

以上过程为实现equals的标准过程。

 

 1 package TomText;
 2 
 3 public class TomText_38 {
 4     private int day;
 5     private int month;
 6     private int year;
 7     public void setDate(int day,int month,int year){        
 8         this.day=day;
 9         this.month=month;
10         this.year=year;
11     }
12     public static void main(String[] args){
13         TomText_38 t=new TomText_38();
14         t.setDate(3, 7, 2018);
15         System.out.println(t.day);
16         System.out.println(t.month);
17         System.out.println(t.year);
18     }
19 
20 }

 

以上过程为实现equals的标准过程

原文:https://www.cnblogs.com/borter/p/9419337.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!