开发者

casting exception

Set cust = customer.getCustomerBills()开发者_运维知识库;
Iterator<Customer> seriter = (Iterator)cust;

I am facing a casting exception when I iterate on Set.

Exception is: org.hibernate.collection.PersistentSet cannot be cast to java.util.Iterator. What am I doing wrong?


You don't cast a collection to Iterator. You obtain one: cust.iterator():

Set<Customer> cust = customer.getCustomerBills();
Iterator<Customer> seriter = cust.iterator();

(A Collection is Iterable, which defines the iterator() method.)


Iterator seriter = (Iterator)cust; is not a proper casting so an exception is being thrown.

use Iterator seriter = cust.iterator();

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜