hashCode方法
hashCode方法
- public int hashCode(){}
- 返回该对象的哈希码值。
- 哈希值根据对象的地址或字符串或数字使用hash算法计算出来的int类型的数值。
- 一般情况下相同对象返回相同哈希码。
public class TestStudent{
public static void main(String[] args){
Student s1 = new Student("aaa", 20);
Student s2 = new Student("bbb", 22);
//hashCode方法
System.out.println(s1.hashCode);
System.out.println(s2.hashCode);
Student s3 = s1;
System.out.println(s3.hashCode);
}
}