Skip to content

Instantly share code, notes, and snippets.

@caratage
Last active May 7, 2018 08:41
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 caratage/d890cd4426ef9a36734d05b2f4df767f to your computer and use it in GitHub Desktop.
Save caratage/d890cd4426ef9a36734d05b2f4df767f to your computer and use it in GitHub Desktop.
Implementation of Java equals function
public class Example {
private int value;
//getters and setters, constructor
@Override
public boolean equals(Object o) {
// same address
if (o == this) return true;
// other type
if (!(o instanceof Example)) {
return false;
}
// cast
Example that = (Example) o;
// check value
return this.value == that.value;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment