Skip to content

Instantly share code, notes, and snippets.

@Marchuck
Created October 4, 2015 11:01
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 Marchuck/a1e59cd435d8c683f8ec to your computer and use it in GitHub Desktop.
Save Marchuck/a1e59cd435d8c683f8ec to your computer and use it in GitHub Desktop.
Effective Java snippets
@Override
public int hashCode(){
int result = 17;
result = 31 * result + someBoolean ? 1:0;
result = 31 * result + someByte;
result = 31 * result + someChar;
result = 31 * result + someShort;
result = 31 * result + someInt;
result = 31 * result + someLong ^ someLong >>> 32 ;
result = 31 * result + Float.floatToIntBits(someFloat);
long doubles = Double.doubleToLongBits(someFloat);
result = 31 * result + doubles ^ doubles >>> 32;
return result;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment