Set cust = customer.getCustomerBills();
Iterator<Customer> seriter = (Iterator)cust;
我在Set上迭代時遇到了鑄造異常。鑄造異常
例外是:org.hibernate.collection.PersistentSet cannot be cast to java.util.Iterator
。我究竟做錯了什麼?
Set cust = customer.getCustomerBills();
Iterator<Customer> seriter = (Iterator)cust;
我在Set上迭代時遇到了鑄造異常。鑄造異常
例外是:org.hibernate.collection.PersistentSet cannot be cast to java.util.Iterator
。我究竟做錯了什麼?
您不會將集合投射到Iterator
。你獲得一個:cust.iterator()
:
Set<Customer> cust = customer.getCustomerBills();
Iterator<Customer> seriter = cust.iterator();
(甲Collection
是Iterable
,它定義了iterator()
方法)
迭代seriter =(迭代)CUST; 不是一個適當的投射,因此拋出異常。
use Iterator seriter = cust.iterator();