[最佳答案] The best implementation? That is a hard question because it depends on the usage pattern. A for nearly all cases reasonable good implementation was proposed in Josh Bloch's Effective Java in item 8. The best thing is to look it up there because the author explains there why the approach is good. A short version Create a int result and assign a non-zero value. For every field f tested in the equals() method, calculate a hash code c by: If the field f is a boolean: calculate (f ? 0 : 1); If the f