public class Contract {
private String contractId;
private String contractName;
private Date begin;
private Date end;
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Contract contract = (Contract) o;
//自己的判断条件是时间段重合的算做同一个对象
return false;
}
@Override
public int hashCode() {
//通过Objects类提供的hash方法
int hash = Objects.hash(contractId, contractName);
return hash;
}
重写equals和hashcode达到HashSet对象集去重的实现
最新推荐文章于 2021-08-17 23:08:53 发布