DEV Community

Discussion on: Hash strings to INT using Java

Collapse
 
bennadel profile image
Ben Nadel

I'm not a Java developer (though I do dip-down into the Java layer from CFML quite often); so, what I'm about to say may be completely wrong; but, I believe I read somewhere that the hashCode isn't necessarily guaranteed to be consistent over time for the same values. Meaning, the underlying algorithm may change with versions of Java. That said, I'm seeing conflicting things in Google about this. Some say that Strings are special case where the algorithm has been codified to be unique; and, some places saying that you should never depend on consistency across executions of the application.

But, I really don't know what I'm talking about - so only take that as something to consider, not something that is fact :D

Collapse
 
gamesover profile image
James Moberg

I checked the application that we used this with and the hashCode values have remained consistently generated since initially used in 2018.

I tested on TryCF.com and discovered that Railo, Lucee 4.5-5 & ColdFusion 10-2021 all return consistent results when passing the same text string.

Collapse
 
bennadel profile image
Ben Nadel

Ok cool -- sorry to cause any momentary panic there. I'm glad I was incorrect in my understanding of things I've read in the past.