JAVA [ 类对象比较 ]
来源:互联网 发布:游大大旅游网 java 编辑:程序博客网 时间:2024/05/18 01:50
public class Customer{
private String name;
private int age;
public Customer(String name,int age){
this.name = name;
this.age = age;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public boolean equals(Object o){
if(this == o) return true;
if(!(o instanceof Customer)) return false;
final Customer other = (Customer)o;
if(this.name.equals(other.getName())&& this.age == other.getAge())
return true;
else
return false;
}
public int hashCode(){
int result;
result = (name == null?0:name.hashCode());
result = 29 * result + age;
return result;
* collection.Customer@03 collection.Customer@04
* hashCode |01| |02| |03| |04| ... |09|
* Object o3 o5 o2
* o1 o4 o6(o7)[通过equals判别]
*/
//if a.equals(b), then a and b must have the same hash code.
}
private String name;
private int age;
public Customer(String name,int age){
this.name = name;
this.age = age;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public boolean equals(Object o){
if(this == o) return true;
if(!(o instanceof Customer)) return false;
final Customer other = (Customer)o;
if(this.name.equals(other.getName())&& this.age == other.getAge())
return true;
else
return false;
}
public int hashCode(){
int result;
result = (name == null?0:name.hashCode());
result = 29 * result + age;
return result;
}
* collection.Customer@03 collection.Customer@04
* hashCode |01| |02| |03| |04| ... |09|
* Object o3 o5 o2
* o1 o4 o6(o7)[通过equals判别]
*/
//if a.equals(b), then a and b must have the same hash code.
}
- JAVA [ 类对象比较 ]
- java类对象的比较
- java 集合类中的对象如何比较
- Java包装类 对象的比较器
- java 对象属性比较工具类
- java中的对象比较
- Java对象的比较
- Java-对象比较器
- java 对象比较
- Java 对象比较
- Java 对象的比较
- java对象的比较
- java对象比较
- Java对象比较
- Java 对象比较
- Java中的对象比较
- 比较两个Java对象
- java 中的对象比较
- Linux跨GCC版本出现“浮点数例外”的解决办法(FC6以后版本)
- 对php中require和include的一点说法
- linux查看命令帮助
- voice of dprk
- 安装vmware tools并在vmware中设置了共享文件夹后,/mnt/hgfs/中仍然不见任何东西
- JAVA [ 类对象比较 ]
- Devpress.XtraGrid.GridControl 笔记
- 如何在ALV中得到对字段有效性检查的结果.
- 好的程序员(转)
- C/C++中printf和C++中cout的输出格式
- shell编程基础 输出helloworld
- 一次library cache pin故障的解决过程
- 改变SQL Server 2005 Express 的身份验证方式
- JAVA [ 配置文件的读取 ]