ClassCastException

I have an Iterator that I need to cast to a ListIterator and when I do this I get a ClassCastException. Can someone tell me why? Thanks.
[143 byte] By [nagarwala] at [2007-10-2 3:01:51]
# 1
> I have an Iterator that I need to cast to a> ListIterator and when I do this I get a> ClassCastException. Can someone tell me why? The underlying implementation of Iterator that you're trying to cast is not a ListIterator.
yawmarka at 2007-7-15 21:28:07 > top of Java-index,Core,Core APIs...
# 2

> I have an Iterator that I need to cast to a

> ListIterator and when I do this I get a

> ClassCastException. Can someone tell me why? Thanks.

The VM can do the job of telling you why quite nicely. Debug it.

Iterator it = ...

System.out.println("This Iterator is really a " + it.getClass());

warnerjaa at 2007-7-15 21:28:07 > top of Java-index,Core,Core APIs...
# 3
hiobject casting--we can cast a sub class to a super class ,but u cant cast a super class to a sub class,in util the iterator is the super class and the listiterator is the sub class.so u cant cast iterator to listiterator
satish_9826a at 2007-7-15 21:28:07 > top of Java-index,Core,Core APIs...
# 4

> object casting--we can cast a sub class to a super

> per class ,but u cant cast a super class to a sub

> class,in util the iterator is the super class and the

> listiterator is the sub class.so u cant cast iterator

> to listiterator

I guess I need some kind of a tutorial to understand your English without going crazy.

aniseeda at 2007-7-15 21:28:07 > top of Java-index,Core,Core APIs...