• Post Reply Bookmark Topic Watch Topic
  • New Topic

Iterator problem  RSS feed

 
Vijay Chandran
Ranch Hand
Posts: 186
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


Dear friends,
This code gives a compiler error: Can only iterate over an array or an instance of java.lang.Iterable

Kindly provide me the explanation of this compiler error

Regards,
Vijay
 
Paul Michael
Ranch Hand
Posts: 697
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The enhanced for loop in Java 5 works with the new Iterable interface which encapsulates an Iterator.

In your example, you are returning an Iterator instead of an Iterable.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!