我用我的自定义设置,MYSET有麻烦,使用工会的基本功能和相交。 程序编译时没有错误,但只返回一个空集。
任何人看到这个问题?
public class MySet<E> extends TreeSet<E> {
Set<E> set;
public MySet(){
set = null;
}
public MySet(Set<E> set){
this.set = set;
}
public void union(Set<E> s){
set.addAll(s);
}
public void intersection(Set<E> s){
set.retainAll(s);
}
}
主要方法
public class TestSet {
public static void main(String[] args) throws FileNotFoundException{
File f1 = new File("courseList1.txt");
File f2 = new File("courseList2.txt");
Scanner scan1 = new Scanner(f1);
Scanner scan2 = new Scanner(f2);
Set<Coarse> set1 = new HashSet<Coarse>();
Set<Coarse> set2 = new HashSet<Coarse>();
MySet<Coarse> mySet = new MySet<Coarse>(set1);
String designator;
int number;
while(scan1.hasNext()){
designator = scan1.next();
number = scan1.nextInt();
set1.add(new Coarse(designator, number));
}
while(scan2.hasNext()){
designator = scan2.next();
number = scan2.nextInt();
set2.add(new Coarse(designator, number));
}
mySet.union(set2);
mySet.intersection(set2);
}
}