Set cust = customer.getCustomerBills();
Iterator<Customer> seriter = (Iterator)cust;
当我迭代 Set 时遇到强制转换异常。
异常(exception)是:org.hibernate.collection.PersistentSet 无法转换为 java.util.Iterator
。我做错了什么?
最佳答案
您不会将集合强制转换为Iterator
。您获得一个:cust.iterator()
:
Set<Customer> cust = customer.getCustomerBills();
Iterator<Customer> seriter = cust.iterator();
(Collection
是 Iterable
,它定义了 iterator()
方法。)
关于java - 类型转换异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4312389/