Не удаляются коты, в чем дело?
package com.javarush.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() {
Set<Cat> result = new HashSet<Cat>();
for(int i = 0; i < 4; i++){
result.add(new Cat());
}
return result;
}
public static Set<Dog> createDogs() {
Set<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) {
Set<Object> set = new HashSet<>();
set.addAll(cats);
set.addAll(dogs);
return set;
}
public static void removeCats(Set<Object> pets, Set<Cat> cats) {
Set copyPets = new HashSet(pets);
for(Object deleted : copyPets){
if(deleted.equals(cats)){
pets.remove(cats);
}
}
}
public static void printPets(Set<Object> pets) {
for(Object cont : pets){
System.out.println(cont);
}
}
public static class Cat{
public Cat(){
}
}
public static class Dog{
public Dog(){
}
}
}