关于Obejct类的hashCode的特点
JAVAAPI原文
* Whenever it is invoked on the same object more than once during an execution of a Java application, the hashCode method must consistently return the same integer, provided no information used in equals comparisons on the object is modified. This integer need not remain consistent from one execution of an application to another execution of the same application.
* If two objects are equal according to the equals(Object) method, then calling the hashCode method on each of the two objects must produce the same integer result.
* It is not required that if two objects are unequal according to the equals(java.lang.Object) method, then calling the hashCode method on each of the two objects must produce distinct integer results. However, the programmer should be aware that producing distinct integer results for unequal objects may improve the performance of hashtables.
翻译
1。在JAVA应用的一次执行过程中,对于同一对象的hashCode方法的多次调用,他们应该返回同样的值(前提是该对象的信息没有发生变化)
2.对于两个对象来说,如果使用equals方法比较返回true,那么这两个对象的hashCode值一定是相同的
3.对于两个对象来说,如果使用equals方法比较返false 那么这两个对象的hashCode值不要求一定不同(可以相同,可以不同),但是如果不用则可以提高应用的性能。。
4.对于Object类来说,不同的Object对象的hashCode值是不同的(Obejct类的hashCode值表示的是对象的地址)