Skip to content

Instantly share code, notes, and snippets.

@JichunMa
Created May 23, 2018 08:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JichunMa/13343ab0d09b787f3061ce1e96701ba5 to your computer and use it in GitHub Desktop.
Save JichunMa/13343ab0d09b787f3061ce1e96701ba5 to your computer and use it in GitHub Desktop.
自定义类indexOf规则自实现方方式(修改equals方法时一定要修改hashCode方法)
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
AreaBean labelBean = (AreaBean) o;
if (label != null ? !label.equals(labelBean.label) : labelBean.label != null) return false;
return value != null ? value.equals(labelBean.value) : labelBean.value == null;
}
@Override
public int hashCode() {
int result = label != null ? label.hashCode() : 0;
result = 31 * result + (value != null ? value.hashCode() : 0);
return result;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment