Hashcode 1231 and 1237


EJB design: Hashcode 1231 and 1237

  1. Hashcode 1231 and 1237 (1 messages)

       Does anyone know why Boolean true(1231) and false(1237) have these hashcodes ?

       The main question is why 1231 for true and why now say 1
    and 1237 for false and why not say 0 or 2.

       Secondly are there any more static predefined values in JDK which have predefined hashCodes ?

  2. Hashcode 1231 and 1237[ Go to top ]

    Probably they were chosen because they are two prime numbers. Since they most probably will have no common divisors with the hashtable size (unless the prime itself divises the hashtable size), the chances of collision in common hashtable implementations would be minimized. That said, 0 and 1 should also work well in most implementations. Perhaps the JLS envisioned some other implementation I can't think of at the moment... or maybe they thought 0 and 1 would be common hash keys, and wanted to chose something else to reduce chances of collision.