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?
Asked
Active
Viewed 313 times
-1

Community
- 1
- 1

user942553
- 1
- 1
-
I doubt you can. But it almost certainly doesn't matter which prime you use anyway. – Louis Wasserman Jan 07 '13 at 21:44
-
1The link points out you want a prime number which is NOT a factor of a power of two for HashMap (which is all of them except 2) – Peter Lawrey Jan 07 '13 at 21:44
-
also, where in that link does it say that you should use a prime other than 31? – Colleen Jan 07 '13 at 21:46
-
Sorry, wrong link. Must be http://stackoverflow.com/questions/1835976/what-is-a-sensible-prime-for-hashcode-calculation/2816747#2816747 – user942553 Jan 08 '13 at 06:55
1 Answers
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