Skip to content

Instantly share code, notes, and snippets.

@geoffreywiseman

geoffreywiseman/School.java

Forked from snellm/School.java
Last active Dec 13, 2015
Embed
What would you like to do?
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
You can’t perform that action at this time.