Skip to content

Instantly share code, notes, and snippets.

@steven7mwesigwa
Created July 4, 2019 12:07
Show Gist options
  • Save steven7mwesigwa/3b191cbeafcb3f9d0260aeeaaf828da7 to your computer and use it in GitHub Desktop.
Save steven7mwesigwa/3b191cbeafcb3f9d0260aeeaaf828da7 to your computer and use it in GitHub Desktop.
package com.stevenmwesigwa.equalsandhashcode.demo1;
public class Person {
private String firstname;
private String lastname;
//Getters
//Setters
@Override
public int hashCode() {
int hash = 7;
hash = 29 * hash + Objects.hashCode(this.firstname);
hash = 29 * hash + Objects.hashCode(this.lastname);
return hash;
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
final Person other = (Person) obj;
if (!Objects.equals(this.firstname, other.firstname)) {
return false;
}
if (!Objects.equals(this.lastname, other.lastname)) {
return false;
}
return true;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment