zhangyufeng0126 2016-06-01 14:04 采纳率: 50%
浏览 1393
已采纳

Generate hash code()and equals()......粗体语句什么意思??

@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + id;
// result = prime * result + ((title == null) ? 0 : title.hashCode());????
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
News other = (News) obj;
if (id != other.id)
return false;
if (title == null) {
if (other.title != null)
return false;
} else if (!title.equals(other.title))
return false;
return true;
}

  • 写回答

3条回答 默认 最新

  • zhangyufeng0126 2016-06-01 14:23
    关注

    为什么如果保留这句语句,就不能依据 ID 排序??

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?