What is a best practice of writing hash function in java?

前端 未结 3 1481
暗喜
暗喜 2020-11-28 06:19

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

3条回答
  •  余生分开走
    2020-11-28 07:09

    It's good, as @leonbloy says, to understand it well. Even then, however, one "best" practice is to simply let your IDE write the function for you. It won't be optimal under some circumstances - and in some very rare circumstances it won't even be good - but for most situations, it's easy, repeatable, error-free, and as good (as a hash code) as it needs to be. Sure, read the docs and understand it well - but don't complicate it unnecessarily.

提交回复
热议问题