我对这些概念很陌生,而且用户很天真,所以请原谅我下面的问题,但是
我想了解java中集合的基本概念
我做了以下课程
package com.vish;
public class HashSetDemo {
private int age;
public HashSetDemo(int age) {
this.age = age;
}
}
现在,我在下面的课程中描述了集合框架
package com.vish;
import java.util.HashSet;
public class HashSetDemo1 {
public static void main(String args[]) {
HashSetDemo hsd = new HashSetDemo(23);
HashSetDemo hsd1 = new HashSetDemo(24);
HashSet<HashSetDemo> hashset = new HashSet<HashSetDemo>();
hashset.add(hsd);
hashset.add(hsd1);
System.out.println(hashset.size());
System.out.println(hashset.contains(hsd));
System.out.println(hashset.contains(new HashSetDemo(23)));
}
}
现在的结果如下
2
true
false
为什么最后一个是假的,当它具有相同的对象引用时
谢谢