Skip to content

Instantly share code, notes, and snippets.

@snellm
Created February 14, 2013 10:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save snellm/4951711 to your computer and use it in GitHub Desktop.
Save snellm/4951711 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 obj) {
return (name.equals(((School) obj).name) || (nickname.equals(((School) obj).nickname)));
}
}
@geoffreywiseman
Copy link

You wrote:

Null safety and typechecking ommitted for clarity

Reproducing that here because I'd forgotten by the time I read the code.

@iamnoah
Copy link

iamnoah commented Feb 14, 2013

return this.class.hashCode();

would be more efficient in heterogenous collections.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment