Created
February 7, 2019 20:02
-
-
Save jerolba/61347bfd967ae2f46fda4c6bf38f8e74 to your computer and use it in GitHub Desktop.
Person class with hashCode and equals
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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