почему валидатор ругается на алгоритм удаления кошек из мира животных?
import java.util.*;
import java.text.*;
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);
System.out.println();
removeCats(pets, cats);
printPets(pets);
}
public static Set<Cat> createCats() {
Set<Cat> result = new HashSet<>();
result.add(new Cat());
result.add(new Cat());
result.add(new Cat());
result.add(new Cat());
return result;
}
public static Set<Dog> createDogs() {
Set<Dog> result = new HashSet<>();
result.add(new Dog());
result.add(new Dog());
result.add(new Dog());
return result;
}
public static Set<Object> join(Set<Cat> cats, Set<Dog> dogs) {
ArrayList<Object> tempPets= new ArrayList<>(cats);
ArrayList<Object> tempDogs= new ArrayList<>(dogs);
tempPets.addAll(tempDogs);
Set<Object> result=new HashSet<>(tempPets);
return result;
}
public static void removeCats(Set<Object> pets, Set<Cat> cats) {
ArrayList<Object> copyPets= new ArrayList<>(pets);
for(int i=0; i<copyPets.size();i++){
if (copyPets.get(i) instanceof Cat) {
pets.remove(copyPets.get(i));
}
}
}
public static void printPets(Set<Object> pets) {
for (Object i:pets) System.out.println(i);
}
public static class Cat {}
public static class Dog {}
}