Set cust = customer.getCustomerBills();
Iterator<Customer> seriter = (Iterator)cust;当我在Set上迭代时,我面临着一个强制转换异常。
例外是:org.hibernate.collection.PersistentSet cannot be cast to java.util.Iterator。我做错了什么?
发布于 2010-11-30 17:57:27
您不会将集合强制转换为Iterator。您将获得一个:cust.iterator()
Set<Customer> cust = customer.getCustomerBills();
Iterator<Customer> seriter = cust.iterator();( Collection是Iterable,它定义iterator()方法。)
发布于 2010-11-30 18:44:44
Iterator seriter = (Iterator)cust;不是正确的强制转换,因此将引发异常。
使用迭代器seriter = cust.iterator();
https://stackoverflow.com/questions/4312389
复制相似问题