Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / December 2005

Tip: Looking for answers? Try searching our database.

foreach =?ISO-8859-1?Q?doesn=B4t_accept_iterator?=

Thread view: 
Hendrik Maryns - 06 Dec 2005 15:03 GMT
Hi,

If I have

final private HashMap<FunctionInputTuple, State> transitions = new
HashMap<FunctionInputTuple, State>();

And elsewhere

for (Entry<FunctionInputTuple, State> transition :
transitions.entrySet().iterator()) {

}

Eclipse gives me the error: Can only iterate over an array or an
instance of java.lang.Iterable.
Why does this not work?  Or is it a bug in Eclipse?

TIA, H.
Signature

Hendrik Maryns

==================
www.lieverleven.be
http://aouw.org

Thomas Fritsch - 06 Dec 2005 15:34 GMT
> If I have
>
[quoted text clipped - 11 lines]
> instance of java.lang.Iterable.
> Why does this not work?  Or is it a bug in Eclipse?

transitions.entrySet() is already the needed instance of Iterable.
Therefore you have to omit .iterator()
  for (Entry<FunctionInputTuple, State> transition :
      transitions.entrySet()) { ... }

BTW: I think instead of  Entry<...>  you have to write  Map.Entry<...>
Signature

"Thomas:Fritsch$ops:de".replace(':','.').replace('$','@')

Thomas Hawtin - 06 Dec 2005 18:40 GMT
>> Eclipse gives me the error: Can only iterate over an array or an
>> instance of java.lang.Iterable.
>> Why does this not work?  Or is it a bug in Eclipse?

It worked in early beta versions of 1.5.0. I believe the rationale for
requiring Iterable and not Iterator, is that it would be less than
obvious that the iterator state is modified. The same goes for passing
iterators to methods. It can be a pain in certain situations.

> BTW: I think instead of  Entry<...>  you have to write  Map.Entry<...>

You can import java.util.Map.Entry;, IIRC. My preference is not to
import more than necessary. Just don't import TreeMap.Entry.

Tom Hawtin
Signature

Unemployed English Java programmer
http://jroller.com/page/tackline/

Hendrik Maryns - 07 Dec 2005 11:32 GMT
Thomas Fritsch schreef:

>> If I have
>>
[quoted text clipped - 16 lines]
>   for (Entry<FunctionInputTuple, State> transition :
>       transitions.entrySet()) { ... }

Yes, I realised ust after posting, and cancelled my post, but not fast
enough, it seems.  Thanks anyway.

> BTW: I think instead of  Entry<...>  you have to write  Map.Entry<...>

Eclipse automatically added the line

import java.util.Map.Entry;

the moment I started about Entries...

H.
Signature

Hendrik Maryns

==================
www.lieverleven.be
http://aouw.org

Roedy Green - 06 Dec 2005 19:46 GMT
On Tue, 06 Dec 2005 16:03:44 +0100, Hendrik Maryns
<hendrik_maryns@despammed.com> wrote, quoted or indirectly quoted
someone who said :

>Eclipse gives me the error: Can only iterate over an array or an
>instance of java.lang.Iterable.
An Iterable is something that can produce a Iterator e.g. a
Collection, not the Iterator itself.  Sun decided not to support all
the things you might naturally expect for : each to support such as
Iterator, Enumeration, char:String, int:String
Signature

Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.