在java中实现hashcode()
作者:互联网
在编写一个用Effective java编写的好hashCode()的指南中,如果字段很长,作者会提到以下步骤.
If the field is a long, compute (int) (f ^ (f >>> 32)).
我无法理解为什么这样做.我们为什么这样做 ?
解决方法:
在Java中,long是64位,int是32位.
所以这只是取高32位,并用低32位对它们进行逐位异或.
标签:effective-java,java,hashcode 来源: https://codeday.me/bug/20190902/1793387.html