hashCode()方法
返回对象的哈希码值,表示在哈希表中的位置。
哈希值根据对象的地址或字符串或数字使用hash算法计算出来的int类型的数值。
一般情况下,相同的对象返回相同的哈希码。
public class hashCode_test {
public static void main(String[] args) {
Student student1 = new Student();
Student student2 = new Student();
Object obj1 = new Object();
System.out.println(student1.hashCode());
System.out.println(student2.hashCode());
System.out.println(obj1.hashCode());
//hashCode()方法返回的是对象的哈希码,不同对象的哈希编码是不一样的(相同类型实例化也不同)
Student student3 = student1;
System.out.println(student3.hashCode());
}
}