public class TestSet {
public static void main(String[] args) {
Set set = new HashSet();
Person p1=new Person();
Person2 p2=new Person2();
set.add(p1);
set.add(p2);
System.out.println(set.size());
}
}
class Person {
@Override
public boolean equals(Object obj) {
return true;
}
}
public class Person2 {
@Override
public boolean equals(Object obj) {
return true;
}
}
我运行的结果是2,不是equals返回true就是同一个元素吗? |
|