Iterator<E> - Iterator cannot be resolved to a type [message #215391] |
Wed, 21 September 2005 11:50  |
Eclipse User |
|
|
|
Hi,
I'm trying to determine if the following is an Eclipse bug, or something
I'm not understanding about generics. Here's the code fragment:
import java.util.LinkedList;
import java.util.List;
public class GenericsInteger {
/**
* @param args
*/
public static void main(String[] args) {
List<Integer> list = new LinkedList<Integer>();
list.add(1);
list.add(4);
list.add(-4);
for (Iterator<Integer> i = list.iterator(); i.hasNext();) {
Integer in = i.next();
System.out.println(in);
}
}
}
In the for loop, the error, " Iterator cannot be resolved to a type",
occurs on the Iterator<Integer> loop init part.
I'm running Eclipse3.1, with jdk1.5.0_05. (I see this is jdk1.5.0_03
also.) I've tried looking at the bug reports, and this forum, but I've
only seen issues with auto-assist templates, ot refactoring.
Thanks for the help,
Frank
|
|
|
|
|
Re: Iterator<E> - Iterator cannot be resolved to a type [message #215413 is a reply to message #215405] |
Wed, 21 September 2005 15:17  |
Eclipse User |
|
|
|
Frank Parrott a écrit :
> Hmmm... I overlooked the obvious! Missed import. Very sorry to have
> taken up your time, but thanks for the help.
> It works now!
No problem.
Note that you don't need to import Iterator if you use the new for loop.
for (Iterator<Integer> i = list.iterator(); i.hasNext();) {
Integer in = i.next();
System.out.println(in);
}
could be written like this:
for (Integer i : list) {
System.out.println(i);
}
You let the compiler taking care of the iteration over the list.
--
Olivier
|
|
|
Powered by
FUDForum. Page generated in 0.25731 seconds