开发者

casting exception

开发者 https://www.devze.com 2023-01-27 08:35 出处:网络
Set cust = customer.getCustomerBills()开发者_运维知识库; Iterator<Customer> seriter = (Iterator)cust;
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

精彩评论

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