Skip to main content



      Home
Home » Language IDEs » Java Development Tools (JDT) » Iterator<E> - Iterator cannot be resolved to a type
Iterator<E> - Iterator cannot be resolved to a type [message #215391] Wed, 21 September 2005 11:50 Go to next message
Eclipse UserFriend
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 #215399 is a reply to message #215391] Wed, 21 September 2005 12:59 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: olivier_thomann.NOca.ibm.comSPAM

Frank Parrott a écrit :
> 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.
Is it a typo or you missed the import for java.util.Iterator?
--
Olivier
Re: Iterator<E> - Iterator cannot be resolved to a type [message #215405 is a reply to message #215399] Wed, 21 September 2005 14:39 Go to previous messageGo to next message
Eclipse UserFriend
Hi Olivier,

Hmmm... I overlooked the obvious! Missed import. Very sorry to have
taken up your time, but thanks for the help.

It works now!

Thanks, frank



Olivier Thomann wrote:
> Frank Parrott a écrit :
>
>> 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.
>
> Is it a typo or you missed the import for java.util.Iterator?
> --
> Olivier
Re: Iterator<E> - Iterator cannot be resolved to a type [message #215413 is a reply to message #215405] Wed, 21 September 2005 15:17 Go to previous message
Eclipse UserFriend
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
Previous Topic:Problems with java.util.List assignments using JDK 1.5
Next Topic:migrate a jbuilder J2EE project (EJB-based) to eclipse?
Goto Forum:
  


Current Time: Fri Jul 25 13:24:15 EDT 2025

Powered by FUDForum. Page generated in 0.25731 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top