Does String.hashCode return the same value on JVM ...
# kotlin-native
n
Does String.hashCode return the same value on JVM and native? It seems that both use the same polynomial hash implementation. Maybe it was a conscious design decision and one could rely on it?
r
I don't know, but since no-body else responded, I'll give my dime 😉 Even if it was, I would never rely on such a design. If you have the need for such a design I'd implement it myself - that said I'd be inclined to be highly skeptical that such a design is a good idea, at least until I see some good arguments
n
Thanks Rohde! I can implement it, but it looks like it'd be the same thing. String.hashCode() is documented in javadoc and is stable. And I've been checking the polyHash functions in k/n runtime, seems to do the same. But likely 10x faster than my implementation 😅
r
Wouldn't surprise me if it's faster 🙂 Design-wise I'm wondering about the case where it's relevant it's identical? The only case I can think of right now is if you want to check if the data is likely to be the same across systems in a fast way. Otherwise I'd rely on the underlying data anyway, and only expect it to be consistent in its respective process
n
It's a rare use case I guess, I am passing data between JVM and K/N within the same app. They communicate through JNI which has some restrictions about what you can pass, and I think that
Int
is a good option for some of this data. I would be more scared to rely on this for anything "distributed" though