|
|||||||
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
#1 |
|
Member (4 bit)
Join Date: Jun 2006
Posts: 12
|
Java iterators and casting
Suppose i have the following code:
Code:
for ( Iterator it produces the following code: Code:
for ( T t :(Iterable Unchecked cast: MyCollection to java.lang.Iterable Can i overcome this unchecked cast somehow? myList.iterator() function returns Iterator |
|
|
|
|
|
#2 |
|
Barefoot on the Moon!
Staff
Premium Member
Join Date: Aug 2002
Location: Northeastern USA
Posts: 13,385
|
A for-loop is primarily utilized incrementing/decrementing integers. If I recall, the Iterator is best used in a while loop.
__________________
There are two secrets to staying young, being happy, and achieving success. You have to laugh and find humor every day, and you have to have a dream.
|
|
|
|
|
|
#3 |
|
Member (7 bit)
Join Date: Aug 2003
Location: Hinckley in Leicestershire
Posts: 110
|
I'm fairly new to Java so this may be totally wrong, but have you implemented the iterable interface?
So.. Code:
public class MyClassName implements Iterable Code:
for ( T t : myList )
T element = t;
|
|
|
|
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|