对象的hashcode值相等,对象内容不一定是相等的。
比如a.hashcode和Inter类型的97.hashcode 结果都是97
但是对象的值相等,hashcode值是一定相等的
比如 String a = "a"; String b = "a" 那a和b的hashcode值当然一定相等
首先equals用来比较对象的时候 源码里写的就是==,那比较的是内存地址嘛。
那两个都是new出来的对象,通过equals比较当然是flase。
那为什么重新equals就一定要重写hashcode呢?
那为了保持equals相等hashcode也相等 所以就必须一起重写。