Java重写equals方法 Li.032
未重写前equals是比较引用的地址, 如比较2个对象, 地址一定是不同的 重写后, 可以比较对象的属性相同, 则认为对象相同 public class Demo1_Object { private int age; private String name; Demo1_Object(){} Demo1_Object(int age,String name){ this.age = age; this.name = name; } public static void main(String[] args) { Demo1_Object d = new Demo1_Object(12, "xiaoming"); Demo1_Object d2 = new Demo1_Object(12, "xiaohong"); Demo1_Object d3 = new Demo1_Object(12, "xiaoming"); System.out.println(d.equals(d2)); System.out.println(d.equals(d3)); } public boolean equals(Object obj){ // 重写Object 类中equals方法 if( obj instanceof Demo1_Object ){ Demo1_Object demo = (Demo1_Object)obj; return this....