Skip to content

Instantly share code, notes, and snippets.

@prashant4224
Last active May 30, 2020 17:24
Show Gist options
  • Save prashant4224/9cab94fa30a4ae18586012d5f0dfa8f1 to your computer and use it in GitHub Desktop.
Save prashant4224/9cab94fa30a4ae18586012d5f0dfa8f1 to your computer and use it in GitHub Desktop.
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