O. Ziggy wrote:Thanks Henry. I thought that since the List provides the Iterator it will returned a typed iterator.
The iterator() method returns an object. It is you who declared the iterator reference and assigned it. There is no way to create a class, with a method, that returns an object, that can control how it will be assigned. If you want to create an iterator reference, that doesn't use generics, the compiler can't stop you. It just does what you want.
O. Ziggy wrote:Ok here is one that has confused me again:
This works fine and produces the output 5234252342. How come i didnt have to cast the i.next() call?
Ok i think in the compiler is not asking for a cast in the above example because the value is not being assigned to another reference. It just calls the toString() which will call the overriden toString() method of what ever instance the returned object is. right?