简体   繁体   English

Java 中 python 的原生 hash() 函数的确切等价物是什么?

[英]What's the exact equivalent of python's native hash() function in Java?

I am trying to convert a Python script I wrote to Java.我正在尝试将我编写的 Python 脚本转换为 Java。 In the script I am using python's native hash() function on strings.在脚本中,我在字符串上使用 python 的本机 hash() 函数。 I need to find the exact equivalent of this in Java to avoid discrepancies.我需要在 Java 中找到与此完全相同的内容,以避免出现差异。 Thanks in advance!提前致谢!

The Python method hash(object) Python 方法hash(object)

calls __hash__() method of an object which are set by default for any object.调用对象的__hash__()方法,该方法默认为任何对象设置。


The exact equivalent in Java to that is Objects.hashCode(Object) that calls hashCode() on the given object and returns the result. Java 中与之完全相同的是Objects.hashCode(Object)hashCode()给定的对象调用hashCode()并返回结果。


The equivalence is given by the syntax.等价由语法给出。 It may not be given by the underlying hashing algorithm.它可能不是由底层散列算法给出的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM