-1

I read using another prime then 31 for hash code generation is better. How can I change the value in Eclipse of the hashCode generator to another value then 31?

Community
  • 1
  • 1

1 Answers1

0

This is probably too obvious, but unless you are generating a very large number of classes that override equals and hashCode, you could just manually edit the Eclipse code to substitute your own prime.

Change the line:

final int prime = 31;

to

final int prime = 61;

or whatever prime you prefer. However, I think you would be better off sticking with 31, because any use of hashCode is likely to have been tested with it.

Patricia Shanahan
  • 25,849
  • 4
  • 38
  • 75
  • We have a large number of developers and it would be nice if in eclipse preferences (which are mandatory loaded by them all) the hashcode is changed. Reconsidering it would even be nicer to change the hashcode generated code itself, so it can use generic code (e.g. a global constant which defines the prime). – user942553 Jan 08 '13 at 06:58