removeCats方法到底哪里出了问题啊?
package zh.codegym.task.task08.task0820;
import java.util.*;
/*
动物集
*/
public class Solution {
public static void main(String[] args) {
Set<Cat> cats = createCats();
Set<Dog> dogs = createDogs();
Set<Object> pets = join(cats, dogs);
printPets(pets);
removeCats(pets, cats);
printPets(pets);
}
public static Set<Cat> createCats() {
HashSet<Cat> result = new HashSet<Cat>();
for(int i=0;i<4;i++)
result.add(new Cat());
//在此编写你的代码
return result;
}
public static Set<Dog> createDogs() {
//在此编写你的代码
HashSet<Dog> result = new HashSet<Dog>();
for(int i=0;i<3;i++)
result.add(new Dog());
return result;
}
public static Set<Object> join(Set<Cat> cats, Set<Dog> dogs) {
//在此编写你的代码
HashSet<Object> set=new HashSet<>();
set.addAll(cats);
set.addAll(dogs);
return set;
}
public static void removeCats(Set<Object> pets, Set<Cat> cats) {
Set<Object> copy=new HashSet<>(pets);
Iterator<Object> iterator=pets.iterator();
Iterator<Cat> cat=cats.iterator();
while (iterator.hasNext()){
Object o=iterator.next();
if(cat.next().equals(o))
pets.remove(o);
}
}
public static void printPets(Set<Object> pets) {
//在此编写你的代码
for(Object x:pets)
System.out.println(x);
}
//在此编写你的代码
public static class Cat{
}
public static class Dog{
}
}