private ArrayList<HashSet<Integer>> sets = new ArrayList<HashSet<Integer>>();
Iterator i = this.sets.iterator();
while (i.hasNext()){
if(i.next().containsAll(union)){
return true;
}
}
I get the following exception as it asssumes .next() gets an object of type Object
Exception in thread "main" java.lang.Error: Unresolved compilation problems:
Type mismatch: cannot convert from Object to HashSet<Integer>
The method containsAll(HashSet<Integer>) is undefined for the type Object
While I get the object Hash set
while (i.hasNext()){
System.out.println(i.next().getClass().getName());
}
prints
java.util.HashSet
java.util.HashSet
java.util.HashSet
What’s going on ?
Make sure your Iterator also as type of
HashSet