Skip to content

Instantly share code, notes, and snippets.

@geoffreywiseman
Forked from snellm/School.java
Last active December 13, 2015 18:08
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 geoffreywiseman/4953036 to your computer and use it in GitHub Desktop.
Save geoffreywiseman/4953036 to your computer and use it in GitHub Desktop.
public class School {
private final String name;
private final String nickname;
public School(String name, String nickname) {
this.name = name;
this.nickname = nickname;
}
@Override
public int hashCode() {
return 1;
}
@Override
public boolean equals(Object other) {
if( other instanceof School ) {
School otherSchool = (School) other;
return nullSafeEquals( name, other.name ) || nullSafeEquals( nickname, other.nickname );
}
return false;
}
private boolean nullSafeEquals( Object alpha, Object beta ) {
// Could be Object.equals() in Java 7.
return alpha == beta || ( alpha != null && alpha.equals( beta ) );
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment