Skip to content

Instantly share code, notes, and snippets.

@yanhua365
Created November 25, 2013 08:19
Show Gist options
  • Save yanhua365/7638087 to your computer and use it in GitHub Desktop.
Save yanhua365/7638087 to your computer and use it in GitHub Desktop.
用Guava简化equals,hashCode和toString的编写。
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
UpdateConfig that = (UpdateConfig) o;
return Objects.equal(fromVersion, that.fromVersion)
&& Objects.equal(targetVersion, that.targetVersion);
}
@Override
public int hashCode() {
return Objects.hashCode(fromVersion, targetVersion);
}
@Override
public String toString() {
return Objects.toStringHelper(this)
.add("id", id)
.add("fromVersion", fromVersion)
.add("targetVersion", targetVersion)
.add("versionType", versionType)
.add("desc", desc)
.toString();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment