This discussion is archived
1 Reply Latest reply: Dec 11, 2012 10:27 AM by jtahlborn RSS

ClassCastException with JDK7U5 while using Iterator.

979285 Newbie
Currently Being Moderated
Hi All,

While i am trying to iterate through a raw Collection (without generics) which contains my business objects using Iterator. It is throwing ClassCastException when i am casting the Iterator's next value with expected object.
but when i replace Iterator with for(int i=0; i<collection.size();i++) loop its working fine and i am able to iterate the collection without any exception and i am able to cast my object with expected class type.

I am not sure why this is happening with JDK1.7u5 while the same code(with iterator) works fine in JDK1.6u31.

Please suggest me the solution or workaround for the same.

Thanks .


  • Correct Answers - 10 points
  • Helpful Answers - 5 points