Skip to content

Instantly share code, notes, and snippets.

@gabrieleboccarusso
Created May 7, 2022 17:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gabrieleboccarusso/23af5a71156b42b50b6a42113f7de68a to your computer and use it in GitHub Desktop.
Save gabrieleboccarusso/23af5a71156b42b50b6a42113f7de68a to your computer and use it in GitHub Desktop.
compare custom objects between each other
// this is also useful for things like MyObj.contain(instance)
@Override
public boolean equals(Object compared) {
boolean flag = false;
if (this == compared) {
flag = true;
} else if (compared instanceof MyObj) {
Book comparedMyObj = (MyObj) compared;
flag = this.astring.equals(comparedMyObj.getAstring()) &&
this.val == comparedMyObj.getVal();
}
return flag;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment