private ArrayList<HashSet<Integer>> sets = new ArrayList<HashSet<Integer>>();
Iterator i = this.sets.iterator();
while (i.hasNext()){
if(i.next().containsAll(union)){
return true;
}
}
我得到以下异常,因为它假设 .next() 获取 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.hasNext()){
System.out.println(i.next().getClass().getName());
}
印刷
java.util.HashSet
java.util.HashSet
java.util.HashSet
这是怎么回事 ?