Why this doesn't work ?
package pl.codegym.task.task08.task0820;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;
/*
Zwierzęcy secik
*/
public class Solution {
public static void main(String[] args) {
Set<Kot> koty = utworzKoty();
Set<Pies> psy = utworzPsy();
Set<Object> zwierzeta = dolacz(koty, psy);
printZwierzeta(zwierzeta);
usunKoty(zwierzeta, koty);
printZwierzeta(zwierzeta);
}
public static Set<Kot> utworzKoty() {
HashSet<Kot> koty = new HashSet<Kot>();
Kot kot1 = new Kot();
Kot kot2 = new Kot();
Kot kot3 = new Kot();
Kot kot4 = new Kot();
koty.add(kot1);
koty.add(kot2);
koty.add(kot3);
koty.add(kot4);
return koty;
}
public static Set<Pies> utworzPsy() {
HashSet<Pies> psy = new HashSet<Pies>();
Pies pies1 = new Pies();
Pies pies2 = new Pies();
Pies pies3 = new Pies();
psy.add(pies1);
psy.add(pies2);
psy.add(pies3);
return psy;
}
public static Set<Object> dolacz(Set<Kot> koty, Set<Pies> psy) {
HashSet<Object> animals = new HashSet<>();
animals.add(koty);
animals.add(psy);
return animals;
}
public static void usunKoty(Set<Object> zwierzeta, Set<Kot> koty) {
zwierzeta.removeAll(koty);
}
public static void printZwierzeta(Set<Object> zwierzeta) {
for(Object x : zwierzeta){
System.out.println(x);
}
}
public static class Kot{
}
public static class Pies{
}
}