这段代码看不懂,为什么结果是ture啊。主要不懂的是:remove方法底层也是依赖于元素的equals方法。什么意思?
import java.util.*;
class Person
{
private String name;
private int age;
Person(String name,int age)
{
this.name = name;
this.age = age;
}
public boolean equals(Object obj)
{
Person p = (Person)obj;
return this.name.equals(p.name) && this.age == p.age;
}
}
class ArrayListTest
{
public static void sop(Object obj)
{
System.out.println(obj);
}
public static void main(String[] args)
{
ArrayList al = new ArrayList();
al.add(new Person("lisi03",33));
sop(al.remove(new Person("lisi03",33)));
//remove方法底层也是依赖于元素的equals方法。
}
} |
|