We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
这个问题需要分两种情况来思考:对象有没有重写equals方法。如果没有,那默认使用Object中的equals做判断,Object中的equals使用的==来判断,比较的是对象在堆中的内存地址。如果对象为String类型,那么equals为true;否则不一定相等。Java中的HashCode是通过一定的规则将与对象相关的信息(内存地址,对象的字段等)映射成一个数值,这个数值称为散列值。我们知道这个hashCode的生成规则之后就不难理解为什么JDK要求(没有强制)当重写了hashCode之后要重写equals方法,来保证当两个对象的hashCode相同时,equals也为true。
The text was updated successfully, but these errors were encountered:
No branches or pull requests
这个问题需要分两种情况来思考:对象有没有重写equals方法。如果没有,那默认使用Object中的equals做判断,Object中的equals使用的==来判断,比较的是对象在堆中的内存地址。如果对象为String类型,那么equals为true;否则不一定相等。Java中的HashCode是通过一定的规则将与对象相关的信息(内存地址,对象的字段等)映射成一个数值,这个数值称为散列值。我们知道这个hashCode的生成规则之后就不难理解为什么JDK要求(没有强制)当重写了hashCode之后要重写equals方法,来保证当两个对象的hashCode相同时,equals也为true。
The text was updated successfully, but these errors were encountered: