java基础知识点---equal,==,hashcode

时间:2023-03-09 07:26:35
java基础知识点---equal,==,hashcode

1.==比较对象之间的地址是否相同

student a=new student(1);

student b=new student(1);

a==b   false

b=a;

a==b   true

2.equals没覆盖前和==相同

string覆盖了equals方法

String a=new String ("你好");

String b=new String ("你好");

a==b            false

a.equals(b)   true

3hashcode 默认情况下,Object中的hashCode() 返回对象的32位jvm内存地址。也就是说如果对象不重写该方法,则返回相应对象的32为JVM内存地址。