在java中编写哈希函数的最佳实践是什么? [英] What is a best practice of writing hash function in java?

查看:24
本文介绍了在java中编写哈希函数的最佳实践是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道在 java 中编写 #hashCode() 方法的最佳实践是什么.可以在此处找到好的描述.有那么好吗?

I'm wondering what is the best practice for writing #hashCode() method in java. Good description can be found here. Is it that good?

推荐答案

有效的 Java.在你理解了生成一个好的哈希函数背后的理论之后,你可以查看 HashCodeBuilder 来自 Apache commons lang,它实现了书中描述的内容.来自文档:

A great reference for an implementation of hashCode() is described in the book Effective Java. After you understand the theory behind generating a good hash function, you may check HashCodeBuilder from Apache commons lang, which implements what's described in the book. From the docs:

这个类启用一个好的hashCode为任何类构建的方法.它遵守书中规定的规则Joshua Bloch 的 Effective Java.编写一个好的 hashCode 方法是其实挺难的.这个班旨在简化流程.

This class enables a good hashCode method to be built for any class. It follows the rules laid out in the book Effective Java by Joshua Bloch. Writing a good hashCode method is actually quite difficult. This class aims to simplify the process.

这篇关于在java中编写哈希函数的最佳实践是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆