Language Design – things not to do 2

Don’t make the behaviour of your strings depend on the system time! (Java String hashCodes I’m looking at you).

It seems like this is new in Java7, and is for security reasons (mostly to stop DOS attacks on hashmaps). So perhaps it could have been abstracted? Instead of putting the code into String.class, call a native method for the string hash seed, and let the JVM control the String hashCode policy? It is yet another source of non-detrminism in the core language.

Leave a Reply

Your email address will not be published. Required fields are marked *