Last active
May 30, 2020 17:24
-
-
Save prashant4224/9cab94fa30a4ae18586012d5f0dfa8f1 to your computer and use it in GitHub Desktop.
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 User { | |
private int id; | |
private String name; | |
//setters & getters | |
@Override | |
public int hashcode() { | |
final int prime = 31; | |
int result = 1; | |
result = prime * result + id; | |
result = prime * result + ((name == null) ? 0 : name.hashcode()); | |
} | |
@Override | |
public boolean equals(Object obj) { | |
if (this == obj) | |
return true; | |
if (obj == null) | |
return false; | |
if (getClass() != obj.getClass()) | |
return false; | |
User user = (User)obj; | |
if (id != user.id) | |
return false; | |
if (name == null) { | |
if (user.name != null) | |
return false; | |
} else if (!name.equals(user.name)) { | |
return false; | |
return true; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment