hibernate 中的equals , hashcode重写

thcthc2 2012-11-19 10:50:37
public boolean equals(Object obj) {
if(this == obj)//this是什么。obj又是哪一个的对象?
return true;
if(obj == null)
return false;
if(getClass() != obj.getClass())
return false;
Order other = (Order)obj;
if(id == null){
if(other.id != null)
return false;
}else if(!id.equals(other.id))
return false;
return true;
}

public int hashCode() {
final int prime = 31;//prime是什么意思为什么为31;
int result = 1;//result为什么赋值为1
result = prime*result +((id == null)?0:id.hashCode());
return result;
}

上面的这个代码是什么意思?一直不能理解。怎么弄。
...全文
69 回复 打赏 收藏 转发到动态 举报
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复

25,985

社区成员

发帖
与我相关
我的任务
社区描述
高性能WEB开发
社区管理员
  • 高性能WEB开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧