Skip to content

Instantly share code, notes, and snippets.

@jerolba
Created February 7, 2019 20:02
Show Gist options
  • Save jerolba/61347bfd967ae2f46fda4c6bf38f8e74 to your computer and use it in GitHub Desktop.
Save jerolba/61347bfd967ae2f46fda4c6bf38f8e74 to your computer and use it in GitHub Desktop.
Person class with hashCode and equals
public class Person {
private Integer id;
private String name;
public Person(Integer id, String name) {
this.id = id;
this.name = name;
}
public int hashCode() {
return Objects.hash(id);
}
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
Person other = (Person) obj;
return Objects.equals(id, other.id);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment