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();
精彩评论